Debian Codegraph @

.github/workflows/release.yml

raw
1 name: Prepare release branch
2
3 on:
4 workflow_dispatch:
5 pull_request_target:
6 types:
7 - closed
8
9 permissions:
10 contents: write
11 pull-requests: write
12
13 jobs:
14 prepare:
15 if: ${{ github.event_name == 'workflow_dispatch' }}
16 runs-on: ubuntu-latest
17 env:
18 GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
19
20 outputs:
21 version: ${{ steps.version-label.outputs.version }}
22
23 steps:
24 - uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd # v5.0.1
25 with:
26 submodules: true
27
28 - name: Configure Git
29 run: |
30 git config --local user.email "[email protected]"
31 git config --local user.name "Actions Auto Build"
32
33 - name: Get current version
34 id: version-label
35 run: |
36 VERSION=$(grep version Cargo.toml | head -n 1 | cut -d'"' -f2)
37 echo "version=${VERSION}" >> $GITHUB_OUTPUT
38
39 - name: Get previous version
40 id: previous-version-label
41 run: |
42 PREVIOUS_VERSION=$(gh api "/repos/${{ github.repository }}/tags?per_page=1" | jq -r '.[] | .name?')
43 echo "previous_version=${PREVIOUS_VERSION}" >> $GITHUB_OUTPUT
44
45 - name: Generate Release Notes
46 id: generate-release-notes
47 run: |
48 generate() {
49 gh api \
50 --method POST \
51 -H "Accept: application/vnd.github+json" \
52 -H "X-GitHub-Api-Version: 2022-11-28" \
53 /repos/${{ github.repository }}/releases/generate-notes \
54 -f tag_name='v${{ steps.version-label.outputs.version }}' \
55 -f previous_tag='v${{ steps.previous-version-label.outputs.previous_version }}' \
56 | jq -r ".body"
57 }
58 echo "changelog<<EOF"$'\n'"$(generate)"$'\n'EOF >> $GITHUB_OUTPUT
59
60 - name: Update CHANGELOG.md
61 run: |
62 echo "# [v${{ steps.version-label.outputs.version }}] - `date +%Y-%m-%d`" >> CHANGELOG.md.tmp
63 cat <<'EOF' >> CHANGELOG.md.tmp
64
65 ${{steps.generate-release-notes.outputs.changelog}}
66
67 ---snip---
68
69 EOF
70 cat CHANGELOG.md >> CHANGELOG.md.tmp
71 mv CHANGELOG.md.tmp CHANGELOG.md
72
73 - name: Update README
74 run: |
75 cargo run --example update-readme
76
77 - name: Commit Changelog and README
78 run: git add -f CHANGELOG.md README.md
79
80 - name: Create Pull Request
81 id: cpr
82 uses: peter-evans/create-pull-request@c0f553fe549906ede9cf27b5156039d195d2ece0 # v8.1.0
83 with:
84 commit-message: "CHANGELOG.md: add generated portion."
85 title: "Release v${{ steps.version-label.outputs.version }}."
86 body: >
87 This is an automated PR to prepend the automated changelog
88 to CHANGELOG.md.<br/>
89 Please review the changes and adapt them into the changelog proper.
90 delete-branch: true
91 labels: release
92 branch: "release/v${{ steps.version-label.outputs.version }}"