-
Notifications
You must be signed in to change notification settings - Fork 0
90 lines (75 loc) · 2.82 KB
/
go.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
# This workflow will build a golang project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go
name: Go
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.22'
- name: Build
run: cd serverlet ; go build -v
- name: Test
run: go test -v ./...
- name: Upload Artifact
uses: actions/upload-artifact@v4
with:
name: serverlet
path: serverlet/serverlet
release:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.22'
- name: Build
run: |
BUILD_TIME=`date -u '+%Y-%m-%d_%H:%M:%S'`
COMMIT_HASH=`git rev-parse --short HEAD`
cd serverlet ; go build -v -ldflags "-s -w -X 'main.BuildTime=$BUILD_TIME' -X 'main.GitCommitHash=$COMMIT_HASH'"
- name: Test
run: go test -v ./...
- name: Remove Old ReleaseAsset
run: |
RELEASE_ID=`curl -L \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/PichuChen/hatsuaki/releases/tags/nightly | jq '.id'`
ASSETS_ID=`curl -L \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/PichuChen/hatsuaki/releases/$RELEASE_ID/assets | jq '.[].id'`
for id in $ASSETS_ID; do
curl -X DELETE \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/PichuChen/hatsuaki/releases/assets/$id
done
- name: Upload Release Asset
run: |
RELEASE_ID=`curl -L \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/PichuChen/hatsuaki/releases/tags/nightly | jq '.id'`
curl -X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
-H "Content-Type: application/octet-stream" \
--data-binary @serverlet/serverlet \
https://uploads.github.com/repos/PichuChen/hatsuaki/releases/$RELEASE_ID/assets?name=serverlet