forked from furan917/MageComm
-
Notifications
You must be signed in to change notification settings - Fork 0
126 lines (110 loc) · 4.51 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
name: Release
on:
push:
tags:
- 'v*'
workflow_dispatch:
inputs:
tag_name:
description: 'Tag name for the release e.g v1.0.0'
required: true
jobs:
build-and-release:
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.20'
- name: Set GOPATH
run: echo "GOPATH=$(go env GOPATH)" >> $GITHUB_ENV
- name: Download dependencies
run: go mod download
- name: Build assets
run: |
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o magecomm-linux-amd64
GOOS=linux GOARCH=arm64 CGO_ENABLED=0 go build -o magecomm-linux-arm64
GOOS=windows GOARCH=amd64 CGO_ENABLED=0 go build -o magecomm-windows-amd64.exe
GOOS=darwin GOARCH=amd64 CGO_ENABLED=0 go build -o magecomm-darwin-amd64
GOOS=darwin GOARCH=arm64 CGO_ENABLED=0 go build -o magecomm-darwin-arm64
- name: Install jq
run: sudo apt-get install jq
- name: Check if release exists and create or update
id: check_release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
TAG_NAME=${{ github.event.inputs.tag_name || github.ref_name }}
RELEASE_NAME="Release $TAG_NAME"
RELEASE_API_URL="https://api.github.com/repos/${{ github.repository }}/releases"
RELEASE_ID=$(curl --silent --location --header "Authorization: Bearer $GITHUB_TOKEN" \
$RELEASE_API_URL | jq ".[] | select(.tag_name == \"$TAG_NAME\") | .id")
if [ -z "$RELEASE_ID" ]; then
echo "Creating new release..."
RELEASE_RESPONSE=$(curl --silent --location --request POST \
--header "Authorization: Bearer $GITHUB_TOKEN" \
--header "Content-Type: application/json" \
--data "{\"tag_name\": \"$TAG_NAME\", \"name\": \"$RELEASE_NAME\", \"draft\": false, \"prerelease\": false}" \
$RELEASE_API_URL)
else
echo "Updating existing release with ID $RELEASE_ID..."
RELEASE_RESPONSE=$(curl --silent --location --request PATCH \
--header "Authorization: Bearer $GITHUB_TOKEN" \
--header "Content-Type: application/json" \
--data "{\"name\": \"$RELEASE_NAME\", \"draft\": false, \"prerelease\": false}" \
$RELEASE_API_URL/$RELEASE_ID)
fi
if [ "$(echo $RELEASE_RESPONSE | jq -r .upload_url)" != "null" ]; then
UPLOAD_URL=$(echo $RELEASE_RESPONSE | jq -r .upload_url)
echo "UPLOAD_URL=$UPLOAD_URL" >> $GITHUB_ENV
else
echo "Error: Upload URL is null."
exit 1
fi
- name: Upload amd64 linux assets
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ env.UPLOAD_URL }}
asset_path: ./magecomm-linux-amd64
asset_name: magecomm-linux-amd64
asset_content_type: application/octet-stream
- name: Upload arm64 linux assets
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ env.UPLOAD_URL }}
asset_path: ./magecomm-linux-arm64
asset_name: magecomm-linux-arm64
asset_content_type: application/octet-stream
- name: Upload amd64 windows assets
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ env.UPLOAD_URL }}
asset_path: ./magecomm-windows-amd64.exe
asset_name: magecomm-windows-amd64.exe
asset_content_type: application/octet-stream
- name: Upload amd64 darwin assets
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ env.UPLOAD_URL }}
asset_path: ./magecomm-darwin-amd64
asset_name: magecomm-darwin-amd64
asset_content_type: application/octet-stream
- name: Upload arm64 darwin assets
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ env.UPLOAD_URL }}
asset_path: ./magecomm-darwin-arm64
asset_name: magecomm-darwin-arm64
asset_content_type: application/octet-stream