Skip to content

Commit 511ef02

Browse files
committed
ci(.github/workflows/tag.yml): Refactor GitHub Actions for releases
1 parent d0b96a2 commit 511ef02

File tree

2 files changed

+49
-96
lines changed

2 files changed

+49
-96
lines changed

.github/workflows/tag.yml

+47-95
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ name: Release
33
on:
44
push:
55
tags:
6-
- 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10
6+
- 'v*' # Trigger on versioned tags, e.g., v1.0, v20.15.10
77

88
env:
99
BINARY_NAME: "httpprobe"
10+
GO_VERSION: "1.23.3"
1011

1112
jobs:
1213
test:
@@ -18,7 +19,7 @@ jobs:
1819
- name: Set up Go
1920
uses: actions/setup-go@v4
2021
with:
21-
go-version: '1.22.0'
22+
go-version: ${{ env.GO_VERSION }}
2223

2324
- name: Cache Go modules
2425
uses: actions/cache@v3
@@ -60,7 +61,7 @@ jobs:
6061
- name: Set up Go
6162
uses: actions/setup-go@v4
6263
with:
63-
go-version: '1.23.3'
64+
go-version: ${{ env.GO_VERSION }}
6465

6566
- name: Cache Go modules
6667
uses: actions/cache@v3
@@ -71,8 +72,7 @@ jobs:
7172
${{ runner.os }}-go-
7273
7374
- name: Set version
74-
id: version
75-
run: echo "VERSION=$(echo ${{ github.ref }} | cut -d '/' -f 3)" >> $GITHUB_ENV
75+
run: echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
7676

7777
- name: Build
7878
env:
@@ -84,25 +84,22 @@ jobs:
8484
8585
- name: Prepare artifact
8686
run: |
87-
mkdir -p dist
87+
ARTIFACT_NAME="${{ env.BINARY_NAME }}-${{ env.VERSION }}_${{ matrix.platform }}_${{ matrix.arch }}"
88+
OUTPUT_PATH="dist/${ARTIFACT_NAME}"
89+
mkdir -p $OUTPUT_PATH
90+
8891
if [[ "${{ matrix.platform }}" == "windows" ]]; then
89-
BINARY_PATH="bin/${{ env.BINARY_NAME }}.exe"
9092
mv bin/${{ env.BINARY_NAME }} bin/${{ env.BINARY_NAME }}.exe
91-
ARTIFACT_NAME="${{ env.BINARY_NAME }}-${{ env.VERSION }}_${{ matrix.platform }}_${{ matrix.arch }}"
92-
mkdir -p dist/tmp
93-
cp $BINARY_PATH dist/tmp/${{ env.BINARY_NAME }}.exe
94-
cd dist && tar -czf $ARTIFACT_NAME.tar.gz -C tmp .
93+
mv bin/${{ env.BINARY_NAME }}.exe $OUTPUT_PATH/${{ env.BINARY_NAME }}.exe
9594
else
96-
BINARY_PATH="bin/${{ env.BINARY_NAME }}"
97-
ARTIFACT_NAME="${{ env.BINARY_NAME }}-${{ env.VERSION }}_${{ matrix.platform }}_${{ matrix.arch }}"
98-
mkdir -p dist/tmp
99-
cp $BINARY_PATH dist/tmp/${{ env.BINARY_NAME }}
100-
cd dist && tar -czf $ARTIFACT_NAME.tar.gz -C tmp .
95+
mv bin/${{ env.BINARY_NAME }} $OUTPUT_PATH/${{ env.BINARY_NAME }}
10196
fi
10297
98+
# Archive the binary (without extra directories)
99+
tar -czf dist/$ARTIFACT_NAME.tar.gz -C $OUTPUT_PATH .
100+
103101
echo "ARTIFACT_PATH=dist/$ARTIFACT_NAME.tar.gz" >> $GITHUB_ENV
104102
echo "ARTIFACT_NAME=$ARTIFACT_NAME" >> $GITHUB_ENV
105-
shell: bash
106103
107104
- name: Upload Build Artifact
108105
uses: actions/upload-artifact@v4
@@ -127,21 +124,18 @@ jobs:
127124
path: artifacts
128125

129126
- name: Generate Release Body
130-
id: release_body
131127
run: |
132-
echo "body<<EOF" >> $GITHUB_OUTPUT
133-
echo "Changelog:" >> $GITHUB_OUTPUT
134-
git log $(git describe --tags --abbrev=0 2>/dev/null || echo HEAD~10)..HEAD --oneline >> $GITHUB_OUTPUT
135-
echo "EOF" >> $GITHUB_OUTPUT
128+
echo "## Changelog" > release_body.md
129+
git log --pretty=format:"- %s" $(git describe --tags --abbrev=0 2>/dev/null || echo $(git rev-list --max-parents=0 HEAD))..HEAD >> release_body.md
136130
137131
- name: Create Release and Upload Assets
138132
uses: softprops/action-gh-release@v1
139133
with:
140134
token: ${{ secrets.GH_PERSONAL_TOKEN }}
141135
name: Release ${{ github.ref_name }}
142-
body: ${{ steps.release_body.outputs.body }}
136+
body_path: release_body.md
143137
files: artifacts/**/*.tar.gz
144-
138+
145139
update-scoop:
146140
needs: release
147141
runs-on: ubuntu-latest
@@ -156,88 +150,46 @@ jobs:
156150
token: ${{ secrets.GH_PERSONAL_TOKEN }}
157151

158152
- name: Get release version
159-
id: get_version
160153
run: |
161-
# Extract tag name from ref
162154
TAG_NAME="${{ github.ref_name }}"
163-
echo "tag_name=$TAG_NAME" >> $GITHUB_OUTPUT
164-
165-
# Remove 'v' prefix if present for version number
166155
VERSION="${TAG_NAME#v}"
167-
echo "version=$VERSION" >> $GITHUB_OUTPUT
168-
echo "Tag: $TAG_NAME, Version: $VERSION"
156+
echo "tag_name=$TAG_NAME" >> $GITHUB_ENV
157+
echo "version=$VERSION" >> $GITHUB_ENV
169158
170-
- name: Download release assets to compute hashes
159+
- name: Download release assets
171160
run: |
172-
VERSION=${{ steps.get_version.outputs.version }}
173-
TAG_NAME=${{ steps.get_version.outputs.tag_name }}
174161
mkdir -p tmp
175-
176-
# Download assets
177-
curl -L "https://github.com/mrfoh/httpprobe/releases/download/${TAG_NAME}/httpprobe-${TAG_NAME}_windows_amd64.tar.gz" -o tmp/httpprobe-${TAG_NAME}_windows_amd64.tar.gz
178-
curl -L "https://github.com/mrfoh/httpprobe/releases/download/${TAG_NAME}/httpprobe-${TAG_NAME}_windows_386.tar.gz" -o tmp/httpprobe-${TAG_NAME}_windows_386.tar.gz
179-
curl -L "https://github.com/mrfoh/httpprobe/releases/download/${TAG_NAME}/httpprobe-${TAG_NAME}_windows_arm64.tar.gz" -o tmp/httpprobe-${TAG_NAME}_windows_arm64.tar.gz
180-
181-
# Compute SHA256 hashes
182-
AMD64_HASH=$(sha256sum tmp/httpprobe-${TAG_NAME}_windows_amd64.tar.gz | cut -d ' ' -f 1)
183-
I386_HASH=$(sha256sum tmp/httpprobe-${TAG_NAME}_windows_386.tar.gz | cut -d ' ' -f 1)
184-
ARM64_HASH=$(sha256sum tmp/httpprobe-${TAG_NAME}_windows_arm64.tar.gz | cut -d ' ' -f 1)
185-
186-
# Store hashes for later use
187-
echo "amd64_hash=$AMD64_HASH" >> $GITHUB_OUTPUT
188-
echo "i386_hash=$I386_HASH" >> $GITHUB_OUTPUT
189-
echo "arm64_hash=$ARM64_HASH" >> $GITHUB_OUTPUT
190-
id: compute_hashes
162+
for arch in amd64 386 arm64; do
163+
curl -L "https://github.com/mrfoh/httpprobe/releases/download/${{ github.ref_name }}/httpprobe-${{ github.ref_name }}_windows_$arch.tar.gz" -o tmp/httpprobe-${{ github.ref_name }}_windows_$arch.tar.gz
164+
done
191165
192-
- name: Update scoop manifest
166+
- name: Compute SHA256 hashes
193167
run: |
194-
VERSION=${{ steps.get_version.outputs.version }}
195-
196-
# Update version in manifest
197-
jq '.version = env.VERSION' bucket/httpprobe.json > bucket/httpprobe.json.tmp
198-
mv bucket/httpprobe.json.tmp bucket/httpprobe.json
199-
200-
# Update URLs in manifest
201-
jq '.architecture."64bit".url = "https://github.com/mrfoh/httpprobe/releases/download/v" + env.VERSION + "/httpprobe-v" + env.VERSION + "_windows_amd64.tar.gz"' bucket/httpprobe.json > bucket/httpprobe.json.tmp
202-
mv bucket/httpprobe.json.tmp bucket/httpprobe.json
203-
204-
jq '.architecture."32bit".url = "https://github.com/mrfoh/httpprobe/releases/download/v" + env.VERSION + "/httpprobe-v" + env.VERSION + "_windows_386.tar.gz"' bucket/httpprobe.json > bucket/httpprobe.json.tmp
205-
mv bucket/httpprobe.json.tmp bucket/httpprobe.json
206-
207-
jq '.architecture."arm64".url = "https://github.com/mrfoh/httpprobe/releases/download/v" + env.VERSION + "/httpprobe-v" + env.VERSION + "_windows_arm64.tar.gz"' bucket/httpprobe.json > bucket/httpprobe.json.tmp
208-
mv bucket/httpprobe.json.tmp bucket/httpprobe.json
209-
210-
# Update hashes in manifest
211-
jq --arg hash "${{ steps.compute_hashes.outputs.amd64_hash }}" '.architecture."64bit".hash = $hash' bucket/httpprobe.json > bucket/httpprobe.json.tmp
212-
mv bucket/httpprobe.json.tmp bucket/httpprobe.json
213-
214-
jq --arg hash "${{ steps.compute_hashes.outputs.i386_hash }}" '.architecture."32bit".hash = $hash' bucket/httpprobe.json > bucket/httpprobe.json.tmp
215-
mv bucket/httpprobe.json.tmp bucket/httpprobe.json
216-
217-
jq --arg hash "${{ steps.compute_hashes.outputs.arm64_hash }}" '.architecture."arm64".hash = $hash' bucket/httpprobe.json > bucket/httpprobe.json.tmp
218-
mv bucket/httpprobe.json.tmp bucket/httpprobe.json
219-
220-
# Update autoupdate URLs
221-
jq '.autoupdate.architecture."64bit".url = "https://github.com/mrfoh/httpprobe/releases/download/v$version/httpprobe-v$version_windows_amd64.tar.gz"' bucket/httpprobe.json > bucket/httpprobe.json.tmp
222-
mv bucket/httpprobe.json.tmp bucket/httpprobe.json
223-
224-
jq '.autoupdate.architecture."32bit".url = "https://github.com/mrfoh/httpprobe/releases/download/v$version/httpprobe-v$version_windows_386.tar.gz"' bucket/httpprobe.json > bucket/httpprobe.json.tmp
225-
mv bucket/httpprobe.json.tmp bucket/httpprobe.json
226-
227-
jq '.autoupdate.architecture."arm64".url = "https://github.com/mrfoh/httpprobe/releases/download/v$version/httpprobe-v$version_windows_arm64.tar.gz"' bucket/httpprobe.json > bucket/httpprobe.json.tmp
228-
mv bucket/httpprobe.json.tmp bucket/httpprobe.json
168+
for arch in amd64 386 arm64; do
169+
HASH=$(sha256sum tmp/httpprobe-${{ github.ref_name }}_windows_$arch.tar.gz | awk '{print $1}')
170+
echo "${arch}_hash=$HASH" >> $GITHUB_ENV
171+
done
172+
173+
- name: Update Scoop manifest
174+
run: |
175+
jq --arg version "${{ env.version }}" \
176+
--arg amd64 "${{ env.amd64_hash }}" \
177+
--arg i386 "${{ env.386_hash }}" \
178+
--arg arm64 "${{ env.arm64_hash }}" \
179+
'
180+
.version = $version |
181+
.architecture."64bit".url = "https://github.com/mrfoh/httpprobe/releases/download/v" + $version + "/httpprobe-v" + $version + "_windows_amd64.tar.gz" |
182+
.architecture."64bit".hash = $amd64 |
183+
.architecture."32bit".url = "https://github.com/mrfoh/httpprobe/releases/download/v" + $version + "/httpprobe-v" + $version + "_windows_386.tar.gz" |
184+
.architecture."32bit".hash = $i386 |
185+
.architecture."arm64".url = "https://github.com/mrfoh/httpprobe/releases/download/v" + $version + "/httpprobe-v" + $version + "_windows_arm64.tar.gz" |
186+
.architecture."arm64".hash = $arm64
187+
' bucket/httpprobe.json > bucket/httpprobe.json.tmp && mv bucket/httpprobe.json.tmp bucket/httpprobe.json
229188
230189
- name: Commit and push updated manifest
231190
run: |
232191
git config --global user.name "GitHub Actions Bot"
233192
git config --global user.email "github-actions[bot]@users.noreply.github.com"
234-
235193
git add bucket/httpprobe.json
236-
237-
# Check if there are changes to commit
238-
if git diff --staged --quiet; then
239-
echo "No changes to commit"
240-
else
241-
git commit -m "chore: update scoop manifest for ${{ github.ref_name }}"
242-
git push origin main
243-
fi
194+
git commit -m "chore: update scoop manifest for ${{ github.ref_name }} [skip ci]" || exit 0
195+
git push origin main

bucket/httpprobe.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
}
1919
},
2020
"bin": "httpprobe.exe",
21-
"checkver": "github",
21+
"extract_dir": "httpprobe",
22+
"checkver": "github:mrfoh/httpprobe",
2223
"autoupdate": {
2324
"architecture": {
2425
"64bit": {

0 commit comments

Comments
 (0)