Skip to content

Commit fcb98e1

Browse files
committed
fix(release) Use Windows and cargo install git-cliff
1 parent 37189cd commit fcb98e1

File tree

1 file changed

+71
-62
lines changed

1 file changed

+71
-62
lines changed

.github/workflows/release.yml

Lines changed: 71 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ permissions:
2121

2222
jobs:
2323
release:
24-
runs-on: ubuntu-latest
24+
runs-on: windows-latest
2525
name: Create GitHub Release
2626

2727
steps:
@@ -30,96 +30,105 @@ jobs:
3030
with:
3131
fetch-depth: 0
3232

33+
- name: Set up Rust
34+
uses: actions-rust-lang/setup-rust-toolchain@v1
35+
with:
36+
toolchain: stable
37+
38+
- name: Install git-cliff
39+
shell: pwsh
40+
run: |
41+
cargo install git-cliff
42+
git-cliff --version
43+
3344
- name: Extract version
3445
id: version
46+
shell: pwsh
3547
run: |
36-
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
37-
VERSION="${{ github.event.inputs.version }}"
38-
else
39-
# Extract version from tag (e.g., v1.4.0 -> 1.4.0)
40-
VERSION="${GITHUB_REF#refs/tags/v}"
41-
fi
42-
echo "version=$VERSION" >> $GITHUB_OUTPUT
48+
if ($env:GITHUB_EVENT_NAME -eq "workflow_dispatch") {
49+
$env:VERSION = $env:GITHUB_EVENT_INPUTS_VERSION
50+
} else {
51+
$env:VERSION = $env:GITHUB_REF -replace "refs/tags/v", ""
52+
}
53+
echo "version=$env:VERSION" >> $env:GITHUB_OUTPUT
4354
4455
- name: Check for existing changelog
4556
id: changelog_check
57+
shell: pwsh
4658
run: |
47-
VERSION="${{ steps.version.outputs.version }}"
48-
CHANGELOG_FILE="CHANGELOG_${VERSION}.md"
49-
50-
if [ "${{ github.event.inputs.use_existing_changelog }}" = "true" ] && [ -f "$CHANGELOG_FILE" ]; then
51-
echo "changelog_exists=true" >> $GITHUB_OUTPUT
52-
echo "Using existing changelog: $CHANGELOG_FILE"
53-
elif [ -f "$CHANGELOG_FILE" ]; then
54-
echo "changelog_exists=false" >> $GITHUB_OUTPUT
59+
$env:VERSION = "${{ steps.version.outputs.version }}"
60+
$env:CHANGELOG_FILE = "CHANGELOG_$env:VERSION.md"
61+
62+
if ("${{ github.event.inputs.use_existing_changelog }}" -eq "true") -and (Test-Path $env:CHANGELOG_FILE)) {
63+
echo "changelog_exists=true" >> $env:GITHUB_OUTPUT
64+
echo "Using existing changelog: $env:CHANGELOG_FILE"
65+
} elseif (Test-Path $env:CHANGELOG_FILE) {
66+
echo "changelog_exists=false" >> $env:GITHUB_OUTPUT
5567
echo "Changelog file exists but use_existing_changelog is false"
56-
else
57-
echo "changelog_exists=false" >> $GITHUB_OUTPUT
68+
} else {
69+
echo "changelog_exists=false" >> $env:GITHUB_OUTPUT
5870
echo "No changelog file found, will generate with git-cliff"
59-
60-
- name: Install git-cliff
61-
if: steps.changelog_check.outputs.changelog_exists == 'false'
62-
run: |
63-
# Download and install git-cliff
64-
wget -qO- https://github.com/orhun/git-cliff/releases/latest/download/git-cliff-linux-amd64.tar.gz
65-
tar -xzf git-cliff-linux-amd64.tar.gz
66-
sudo mv git-cliff /usr/local/bin/
67-
chmod +x /usr/local/bin/git-cliff
68-
git-cliff --version
71+
}
6972
7073
- name: Generate changelog with git-cliff
7174
if: steps.changelog_check.outputs.changelog_exists == 'false'
75+
shell: pwsh
7276
run: |
73-
VERSION="${{ steps.version.outputs.version }}"
74-
git-cliff --config cliff.toml --tag "v$VERSION" --verbose > CHANGELOG.md
77+
$env:VERSION = "${{ steps.version.outputs.version }}"
78+
git-cliff --config cliff.toml --tag "v$env:VERSION" --verbose > CHANGELOG.md
7579
7680
- name: Format generated changelog
7781
if: steps.changelog_check.outputs.changelog_exists == 'false'
82+
shell: pwsh
7883
run: |
79-
VERSION="${{ steps.version.outputs.version }}"
80-
echo "# Changelog - Version $VERSION" > CHANGELOG_temp.md
81-
echo "" >> CHANGELOG_temp.md
82-
echo "*This changelog was automatically generated using git-cliff*" >> CHANGELOG_temp.md
83-
echo "" >> CHANGELOG_temp.md
84-
cat CHANGELOG.md >> CHANGELOG_temp.md
85-
mv CHANGELOG_temp.md CHANGELOG.md
86-
cp CHANGELOG.md "CHANGELOG_${VERSION}.md"
84+
$env:VERSION = "${{ steps.version.outputs.version }}"
85+
"# Changelog - Version $env:VERSION" | Out-File -Encoding UTF8 CHANGELOG_temp.md
86+
"" | Out-File -Encoding UTF8 -Append CHANGELOG_temp.md
87+
"*This changelog was automatically generated using git-cliff*" | Out-File -Encoding UTF8 -Append CHANGELOG_temp.md
88+
"" | Out-File -Encoding UTF8 -Append CHANGELOG_temp.md
89+
Get-Content CHANGELOG.md | Out-File -Encoding UTF8 -Append CHANGELOG_temp.md
90+
Move-Item CHANGELOG_temp.md CHANGELOG.md
91+
Copy-Item CHANGELOG.md "CHANGELOG_$env:VERSION.md"
8792
8893
- name: Create release notes
8994
id: release_notes
95+
shell: pwsh
9096
run: |
91-
VERSION="${{ steps.version.outputs.version }}"
92-
if [ "${{ steps.changelog_check.outputs.changelog_exists }}" = "true" ]; then
93-
CHANGELOG_FILE="CHANGELOG_${VERSION}.md"
94-
echo "### Release $VERSION" > release_notes.md
95-
echo "" >> release_notes.md
96-
echo "*Using existing \`$CHANGELOG_FILE\`*" >> release_notes.md
97-
echo "" >> release_notes.md
98-
cat "$CHANGELOG_FILE" >> release_notes.md
99-
else
100-
echo "### Release $VERSION" > release_notes.md
101-
echo "" >> release_notes.md
102-
echo "*Automatically generated using git-cliff*" >> release_notes.md
103-
echo "" >> release_notes.md
104-
tail -n +2 CHANGELOG.md >> release_notes.md
105-
fi
106-
echo "notes_file=release_notes.md" >> $GITHUB_OUTPUT
97+
$env:VERSION = "${{ steps.version.outputs.version }}"
98+
99+
if ("${{ steps.changelog_check.outputs.changelog_exists }}" -eq "true") {
100+
$env:CHANGELOG_FILE = "CHANGELOG_$env:VERSION.md"
101+
"### Release $env:VERSION" | Out-File -Encoding UTF8 release_notes.md
102+
"" | Out-File -Encoding UTF8 -Append release_notes.md
103+
"*Using existing ``$env:CHANGELOG_FILE``*" | Out-File -Encoding UTF8 -Append release_notes.md
104+
"" | Out-File -Encoding UTF8 -Append release_notes.md
105+
Get-Content $env:CHANGELOG_FILE | Out-File -Encoding UTF8 -Append release_notes.md
106+
} else {
107+
"### Release $env:VERSION" | Out-File -Encoding UTF8 release_notes.md
108+
"" | Out-File -Encoding UTF8 -Append release_notes.md
109+
"*Automatically generated using git-cliff*" | Out-File -Encoding UTF8 -Append release_notes.md
110+
"" | Out-File -Encoding UTF8 -Append release_notes.md
111+
Get-Content CHANGELOG.md | Select-Object -Skip 2 | Out-File -Encoding UTF8 -Append release_notes.md
112+
}
113+
echo "notes_file=release_notes.md" >> $env:GITHUB_OUTPUT
107114
108115
- name: Create GitHub Release
109116
env:
110117
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
118+
shell: pwsh
111119
run: |
112-
VERSION="${{ steps.version.outputs.version }}"
113-
NOTES_FILE="${{ steps.release_notes.outputs.notes_file }}"
114-
gh release create "v$VERSION" --title "v$VERSION" --notes-file "$NOTES_FILE" --repo "$GITHUB_REPOSITORY"
120+
$env:VERSION = "${{ steps.version.outputs.version }}"
121+
$env:NOTES_FILE = "${{ steps.release_notes.outputs.notes_file }}"
122+
gh release create "v$env:VERSION" --title "v$env:VERSION" --notes-file $env:NOTES_FILE --repo $env:GITHUB_REPOSITORY
115123
116124
- name: Commit new changelog if generated
117125
if: steps.changelog_check.outputs.changelog_exists == 'false'
118-
uses: EndBug/add-and-commit@v9
119-
with:
120-
message: 'chore: Generate changelog for v${{ steps.version.outputs.version }} [skip ci]'
121-
add: '.'
122-
path: 'CHANGELOG_${{ steps.version.outputs.version }}.md'
126+
shell: pwsh
127+
run: |
128+
$env:VERSION = "${{ steps.version.outputs.version }}"
129+
git add "CHANGELOG_$env:VERSION.md"
130+
git commit -m "chore: Generate changelog for v$env:VERSION [skip ci]"
131+
git push
123132
124133
- name: Upload changelog artifact
125134
uses: actions/upload-artifact@v4

0 commit comments

Comments
 (0)