Debian Codegraph @

.github/workflows/release-ready.yml

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