1+ name : Automatic Release Workflow
2+
3+ on :
4+ push :
5+ tags :
6+ - ' [0-9]+.[0-9]+.[0-9]+'
7+ workflow_dispatch :
8+ inputs :
9+ version :
10+ description : ' Version to release (e.g., 1.0.0)'
11+ required : true
12+
13+ jobs :
14+ release :
15+ name : Create Release
16+ runs-on : ubuntu-latest
17+ permissions :
18+ contents : write
19+
20+ steps :
21+ - name : Checkout code
22+ uses : actions/checkout@v3
23+
24+
25+ - name : Set APP_VERSION
26+ id : version
27+ run : |
28+ if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
29+ VERSION=${{ github.event.inputs.version }}
30+ else
31+ VERSION=${{ github.ref }}
32+ VERSION=${VERSION#refs/tags/}
33+ fi
34+ echo "APP_VERSION=$VERSION" >> $GITHUB_ENV
35+
36+ - name : Build Go Application
37+ run : |
38+ mkdir -p ${{ github.workspace }}/packagelock
39+ APP_VERSION=${{ env.APP_VERSION }}
40+ CGO_ENABLED=0 GOOS=linux go build -ldflags "-X 'main.AppVersion=$APP_VERSION'" -o ${{ github.workspace }}/packagelock
41+
42+ - name : Create Release Archive
43+ run : |
44+ mkdir -p release
45+ cp -r ${{ github.workspace }}/packagelock ./release/packagelock
46+ tar -czvf release/packagelock-${{ env.APP_VERSION }}-linux-amd64.tar.gz -C release packagelock
47+
48+ - name : Calculate Checksum
49+ run : |
50+ md5sum ./release/packagelock-${{ env.APP_VERSION }}-linux-amd64.tar.gz | cut -f 1 -d " " > ./release/packagelock-${{ env.APP_VERSION }}-linux-amd64.tar.gz.md5
51+ - name : Get release URL
52+ id : get_release
53+ uses : bruceadams/get-release@v1.3.2
54+ env :
55+ GITHUB_TOKEN : ${{ github.token }}
56+
57+ - name : Upload Release Tarball
58+ id : upload-release-asset
59+ uses : actions/upload-release-asset@v1
60+ env :
61+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
62+ with :
63+ upload_url : ${{ steps.get_release.outputs.upload_url }}
64+ asset_path : ./release/packagelock-${{ env.APP_VERSION }}-linux-amd64.tar.gz
65+ asset_name : packagelock-${{ env.APP_VERSION }}-linux-amd64.tar.gz
66+ asset_content_type : application/gzip
67+
68+ - name : Upload Checksum
69+ id : upload-checksum-asset
70+ uses : actions/upload-release-asset@v1
71+ env :
72+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
73+ with :
74+ upload_url : ${{ steps.get_release.outputs.upload_url }}
75+ asset_path : ./release/packagelock-${{ env.APP_VERSION }}-linux-amd64.tar.gz.md5
76+ asset_name : packagelock-${{ env.APP_VERSION }}-linux-amd64.tar.gz.md5
77+ asset_content_type : text/plain
0 commit comments