-
Notifications
You must be signed in to change notification settings - Fork 0
110 lines (94 loc) · 3.65 KB
/
attach-artifact-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
name: Attach Artifact to Release
on:
pull_request:
types:
- closed
jobs:
attach-to-release:
name: Attach Artifact to Release
if: github.event.pull_request.merged == true
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v3
with:
go-version: '1.21.4'
- name: Get Reusable Script Files
run: |
chmod +x release.sh
- name: Get Artifact ID
id: get-artifact-id
run: echo "artifact_id=$(grep "VtrainVersion" "./pkg/common/utilities.go" | awk -F'"' '{print $2}')" >> $GITHUB_ENV
- name: Backup release body
run: |
release_id=$(curl -X GET -H "Authorization: token ${{ secrets.BOT_TOKEN }}" https://api.github.com/repos/${{ github.repository }}/releases?per_page=1 | jq -r '.[] | select(.name == "${{ env.artifact_id }}") | .id')
# Check if release_id is empty
if [ -z "$release_id" ]; then
echo "Release '$release_name' not found in the repository '$repo'."
exit 1
fi
release_url="https://api.github.com/repos/${{ github.repository }}/releases/$release_id"
curl -X GET -H "Authorization: token ${{ secrets.BOT_TOKEN }}" "$release_url" | jq -r .body > release_body.txt
- name: Store previous release body as artifact
uses: actions/upload-artifact@v2
with:
name: release_body.txt
path: release_body.txt
- name: Delete tag and release
uses: dev-drprasad/[email protected]
with:
tag_name: ${{ env.artifact_id }}
github_token: ${{ secrets.BOT_TOKEN }}
delete_release: true
- name: Install dependencies
run: |
go version
go get
- name: Generate distributions
run: sh release.sh
- name: Upload Windows binaries to release
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.BOT_TOKEN }}
file: vtrain_windows.zip
asset_name: vtrain_windows_$tag.zip
tag: ${{ env.artifact_id }}
overwrite: true
- name: Upload Linux binaries to release
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.BOT_TOKEN }}
file: vtrain_linux.zip
asset_name: vtrain_linux_$tag.zip
tag: ${{ env.artifact_id }}
overwrite: true
- name: Upload macOS Silicon binaries to release
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.BOT_TOKEN }}
file: vtrain_mac_arm.zip
asset_name: vtrain_mac_arm_$tag.zip
tag: ${{ env.artifact_id }}
overwrite: true
- name: Upload macOS Intel binaries to release
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.BOT_TOKEN }}
file: vtrain_mac_intel.zip
asset_name: vtrain_mac_intel_$tag.zip
tag: ${{ env.artifact_id }}
overwrite: true
- name: Get latest release ID
id: get-release
run: |
LATEST_RELEASE=$(curl -X GET -H "Authorization: token ${{ secrets.BOT_TOKEN }}" "https://api.github.com/repos/${{ github.repository }}/releases?per_page=1" | jq -r '.[].id')
echo "Latest Release ID: $LATEST_RELEASE"
echo "RELEASE_ID=$LATEST_RELEASE" >> $GITHUB_ENV
- name: Edit Release
uses: irongut/[email protected]
with:
token: ${{ secrets.BOT_TOKEN }}
id: ${{ env.RELEASE_ID }}
name: ${{ env.artifact_id }}
replacename: true