-
Notifications
You must be signed in to change notification settings - Fork 0
74 lines (66 loc) · 2.67 KB
/
release.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
name: Build and Release
on:
push:
tags:
- 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10
jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.21.5
- name: Check out code into the Go module directory
uses: actions/checkout@v2
- name: Set up environment
run: |
echo "$(go env GOPATH)/bin" >> $GITHUB_PATH
echo $PATH
echo $(go env GOPATH)
- name: Check if release exists
id: check_release
run: |
TAG_NAME=${{ github.ref }} # refs/tags/v0.1.0
TAG_NAME=${TAG_NAME#refs/tags/} # v0.1.0
RELEASE_ID=$(curl --silent --show-error --header "Authorization: token ${{ secrets.PAT }}" "https://api.github.com/repos/${{ github.repository }}/releases/tags/$TAG_NAME" | jq '.id')
IS_PRERELEASE=$(curl --silent --show-error --header "Authorization: token ${{ secrets.PAT }}" "https://api.github.com/repos/${{ github.repository }}/releases/tags/$TAG_NAME" | jq '.prerelease')
echo "RELEASE_ID=$RELEASE_ID" >> $GITHUB_ENV
echo "IS_PRERELEASE=$IS_PRERELEASE" >> $GITHUB_ENV
- name: Build binaries
uses: goreleaser/goreleaser-action@v2
with:
version: latest
args: release
env:
GITHUB_TOKEN: ${{ secrets.PAT }}
IS_PRERELEASE: ${{ env.IS_PRERELEASE }}
# - name: Create Release
# id: create_release
# uses: actions/create-release@v1
# env:
# GITHUB_TOKEN: ${{ secrets.PAT }}
# with:
# tag_name: ${{ github.ref }}
# release_name: Release ${{ github.ref }}
# draft: false
# prerelease: false
# if: env.RELEASE_ID == 'null'
- name: Upload Release Assets
run: |
UPLOAD_URL=$(if [ "${{ env.RELEASE_ID }}" == "null" ]; then echo "${{ steps.create_release.outputs.upload_url }}"; else echo "https://uploads.github.com/repos/${{ github.repository }}/releases/${{ env.RELEASE_ID }}/assets"; fi)
for file in dist/*; do
if [[ -f "$file" ]]; then
filename=$(basename -- "$file")
extension="${filename##*.}"
if [[ "$extension" == "exe" || "$extension" == "tar.gz" ]]; then
echo "Uploading $file"
curl \
--header "Authorization: token ${{ secrets.PAT }}" \
--header "Content-Type: $(file -b --mime-type $file)" \
--data-binary @"$file" \
"$UPLOAD_URL?name=$(basename $file)"
fi
fi
done