-
Notifications
You must be signed in to change notification settings - Fork 0
148 lines (125 loc) · 4.4 KB
/
deploy-head.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
name: "Deploy head"
on:
workflow_run:
workflows:
- CI
types:
- completed
branches:
- main
permissions:
contents: write
deployments: write
jobs:
check:
name: "Check skip"
runs-on: ubuntu-22.04
outputs:
is_newer: ${{ steps.step1.outputs.result }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Check agains head
id: step1
shell: pwsh
run: |
git merge-base --is-ancestor refs/tags/head ${{ github.sha }}
echo "Result: $LASTEXITCODE"
if($LASTEXITCODE -eq 0) {
"result=1" | Out-File -Path $env:GITHUB_OUTPUT -Append
}
elseif($LASTEXITCODE -eq 1) {
"result=0" | Out-File -Path $env:GITHUB_OUTPUT -Append
exit 0
}
tag:
name: "Update tag"
runs-on: ubuntu-22.04
needs: check
if: needs.check.outputs.is_newer == 1
steps:
- uses: actions/checkout@v4
- name: Update head tag
run: |
git push --delete origin head
git tag head
git push origin head
assets:
name: "Upload assets"
runs-on: ubuntu-22.04
needs: check
if: needs.check.outputs.is_newer == 1
strategy:
fail-fast: false
matrix:
platform: [windows, linux]
include:
- platform: windows
arch: x86_64
release-ext: zip
release-type: application/zip
- platform: linux
arch: x86_64
release-ext: tar.gz
release-type: application/gzip
steps:
- name: Download build artifacts
uses: dawidd6/action-download-artifact@v6
with:
workflow: ci.yml
run_id: ${{ github.event.workflow_run.id }}
name: snail-server-${{ matrix.arch }}-${{ matrix.platform }}
path: bin
- name: Repack release asset (zip)
if: matrix.release-ext == 'zip'
run: |
mv ${{ github.workspace }}/bin/info.txt ${{ github.workspace }}/info.txt
zip snail-server-${{ matrix.arch }}-${{ matrix.platform }}.${{ matrix.release-ext }} bin/* info.txt
- name: Repack release asset (tar.gz)
if: matrix.release-ext == 'tar.gz'
run: |
mv ${{ github.workspace }}/bin/info.txt ${{ github.workspace }}/info.txt
tar -cvzf snail-server-${{ matrix.arch }}-${{ matrix.platform }}.${{ matrix.release-ext }} bin info.txt
- name: Upload release asset
shell: pwsh
run: |
$assetId = 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/albertziegenhagel/snail-server/releases/110773624/assets | `
ConvertFrom-Json | `
Where-Object -Property name -Value "snail-server-${{ matrix.arch }}-${{ matrix.platform }}.${{ matrix.release-ext }}" -EQ | `
Select-Object -Expand id
if($assetId) {
curl -L `
-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/albertziegenhagel/snail-server/releases/assets/$assetId
}
curl -i -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: ${{ matrix.release-type }}" `
--data-binary "@snail-server-${{ matrix.arch }}-${{ matrix.platform }}.${{ matrix.release-ext }}" `
"https://uploads.github.com/repos/albertziegenhagel/snail-server/releases/110773624/assets?name=snail-server-${{ matrix.arch }}-${{ matrix.platform }}.${{ matrix.release-ext }}"
publish:
name: "Puplish"
runs-on: ubuntu-22.04
needs:
- tag
- assets
steps:
- uses: actions/checkout@v4
- name: Mark release as non-draft
run: |
curl -L -X PATCH \
-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/albertziegenhagel/snail-server/releases/110773624" \
-d '{"draft":false}'