-
-
Notifications
You must be signed in to change notification settings - Fork 1k
86 lines (77 loc) · 3.05 KB
/
release-ready.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
name: Create release
on:
pull_request:
types: [closed]
jobs:
create_release:
if: ${{ github.event.pull_request.merged == true && startsWith(github.head_ref, 'release-v') }}
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: "master"
- name: Extract version from branch name
id: get_version
run: |
BRANCH="${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}"
if [[ "$BRANCH" =~ release-v([0-9]+\.[0-9]+) ]]; then
VERSION="${BASH_REMATCH[1]}"
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
echo "DISPLAY_VERSION=v$VERSION" >> $GITHUB_OUTPUT
else
echo "Branch name does not match expected format (release-vX.XX)!" && exit 1
fi
- name: Package repository as tar.gz
run: |
VER="${{ steps.get_version.outputs.VERSION }}"
git archive --format=tar.gz -o cloc-$VER.tar.gz HEAD
- name: Get artifact url
id: get_artifact_url
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
ARTIFACT_COMMENT=$(gh pr view ${{ github.event.pull_request.number }} --json comments -q '
.comments
| sort_by(.createdAt)
| reverse
| map(select(.body | contains("**Built executable artifact:**")))
| .[0].body
')
if [ -z "$ARTIFACT_COMMENT" ]; then
echo "No matching comment found."
exit 1
fi
MATCHING_URLS=$(echo "$ARTIFACT_COMMENT" | grep -oP 'https:\/\/[^\s\)]+')
if [ -z "$MATCHING_URLS" ]; then
echo "No URL found in the comment."
exit 1
fi
ARTIFACT_URL=$(echo "$MATCHING_URLS" | head -n 1)
RUN_ID=$(echo "$ARTIFACT_URL" | grep -oP '/actions/runs/\K[0-9]+')
echo "RUN_ID=$RUN_ID" >> $GITHUB_OUTPUT
echo "Artifact URL: $ARTIFACT_URL"
- name: Download artifact
uses: actions/download-artifact@v4
with:
name: cloc-${{ steps.get_version.outputs.VERSION }}-executable
github-token: ${{ secrets.GITHUB_TOKEN }}
run-id: ${{ steps.get_artifact_url.outputs.RUN_ID }}
- name: Prepare renamed release assets
run: |
VER="${{ steps.get_version.outputs.VERSION }}"
cp cloc cloc-$VER.pl
cp Unix/NEWS release_notes-$VER.txt
- name: Create GitHub release with assets
uses: softprops/action-gh-release@v2
with:
tag_name: "${{ steps.get_version.outputs.DISPLAY_VERSION }}"
name: "${{ steps.get_version.outputs.DISPLAY_VERSION }}"
body: "${{ github.event.pull_request.body }}"
token: ${{ secrets.GITHUB_TOKEN }}
files: |
cloc-${{ steps.get_version.outputs.VERSION }}.tar.gz
README.md
cloc-${{ steps.get_version.outputs.VERSION }}.pl
cloc-${{ steps.get_version.outputs.VERSION }}.exe
release_notes-${{ steps.get_version.outputs.VERSION }}.txt