-
Notifications
You must be signed in to change notification settings - Fork 1
171 lines (170 loc) · 6.75 KB
/
Copy pathbuild_server.yml
File metadata and controls
171 lines (170 loc) · 6.75 KB
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
name: build-server
on:
workflow_dispatch:
inputs:
sha_short:
description: 'sha_short'
required: true
new_tag:
description: 'new_tag'
required: true
new_tag_short:
description: 'new_tag_short'
required: true
name:
description: 'name'
required: true
sha:
description: "sha"
required: true
repository_dispatch:
types: [build-server]
jobs:
build-server:
name: Build and release server
runs-on: ubuntu-latest
permissions:
contents: write
if: github.event.inputs.name || github.event.inputs.new_tag
env:
ARTIFACTS: server/dist/reearth_*.*
steps:
- name: Harden Runner
uses: step-security/harden-runner@bf7454d06d71f1098171f2acdf0cd4708d7b5920 # v2.20.0
with:
egress-policy: audit
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
with:
go-version-file: 'server/go.mod'
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@f06c13b6b1a9625abc9e6e439d9c05a8f2190e94 # v7.2.3
with:
distribution: goreleaser
version: latest
args: release ${{ github.event.inputs.new_tag == 'blank' && '--snapshot' || '' }}
workdir: server
env:
GORELEASER_CURRENT_TAG: ${{ github.event.inputs.new_tag == 'blank' && '0.0.0' || github.event.inputs.new_tag }}
- name: Rename artifacts
if: ${{ github.event.inputs.name != 'blank' }}
run: |
for f in $ARTIFACTS; do
newname=$(echo $f | sed -E 's/_0\.0\.0-SNAPSHOT-[^_]*/_${{ github.event.inputs.name }}/')
if [ "$f" != "$newname" ]; then
mv "$f" "$newname"
fi
done
- name: List artifacts
run: ls -l server/dist
- name: Release nightly/rc
if: ${{ github.event.inputs.name != 'blank' }}
uses: ncipollo/release-action@339a81892b84b4eeb0f6e744e4574d79d0d9b8dd # v1.21.0
with:
allowUpdates: true
artifacts: ${{ env.ARTIFACTS }}
commit: ${{ github.event.inputs.sha }}
name: ${{ github.event.inputs.name }}
tag: ${{ github.event.inputs.name }}
body: ${{ github.event.inputs.sha_short }}
prerelease: true
- name: Download latest changelog
if: ${{ github.event.inputs.new_tag != 'blank' }}
uses: dawidd6/action-download-artifact@b6e2e70617bc3265edd6dab6c906732b2f1ae151 # v21
with:
workflow: release.yml
name: changelog-${{ github.event.inputs.new_tag }}
- name: Create GitHub release
if: ${{ github.event.inputs.new_tag != 'blank' }}
uses: ncipollo/release-action@339a81892b84b4eeb0f6e744e4574d79d0d9b8dd # v1.21.0
with:
allowUpdates: true
artifacts: ${{ env.ARTIFACTS }}
commit: ${{ github.event.inputs.sha }}
name: ${{ github.event.inputs.new_tag }}
tag: ${{ github.event.inputs.new_tag}}
bodyFile: CHANGELOG_latest.md
build-docker-image:
name: Build and push Docker image
runs-on: ubuntu-latest
if: ${{ github.event.inputs.name != 'blank' || github.event.inputs.new_tag != 'blank' }}
env:
IMAGE_NAME: reearth/reearth
defaults:
run:
working-directory: server
steps:
- name: Harden Runner
uses: step-security/harden-runner@bf7454d06d71f1098171f2acdf0cd4708d7b5920 # v2.20.0
with:
egress-policy: audit
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3.2.0
id: app-token
with:
app-id: ${{ vars.GH_APP_ID }}
private-key: ${{ secrets.GH_APP_PRIVATE_KEY }}
- name: Set up QEMU
uses: docker/setup-qemu-action@96fe6ef7f33517b61c61be40b68a1882f3264fb8 # v4.2.0
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@bb05f3f5519dd87d3ba754cc423b652a5edd6d2c # v4.2.0
- name: Login to DockerHub
uses: docker/login-action@dbcb813823bdd20940b903addbd779551569679f # v4.6.0
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Get options
id: options
env:
TAG: ${{ github.event.inputs.new_tag_short && github.event.inputs.new_tag_short != 'blank' && github.event.inputs.new_tag_short || '' }}
NAME: ${{ github.event.inputs.name }}
SHA: ${{ github.event.inputs.sha_short }}
run: |
if [[ -n $TAG ]]; then
PLATFORMS=linux/amd64,linux/arm64
VERSION=$TAG
TAGS=$IMAGE_NAME:$TAG
if [[ ! $TAG =~ '-' ]]; then
TAGS+=,${IMAGE_NAME}:${TAG%.*}
TAGS+=,${IMAGE_NAME}:${TAG%%.*}
TAGS+=,${IMAGE_NAME}:latest
fi
else
PLATFORMS=linux/amd64
VERSION=$SHA
TAGS=$IMAGE_NAME:$NAME
fi
echo "::set-output name=platforms::$PLATFORMS"
echo "::set-output name=version::$VERSION"
echo "::set-output name=tags::$TAGS"
- name: Fetch reearth-web release
uses: dsaltares/fetch-gh-release-asset@aa2ab1243d6e0d5b405b973c89fa4d06a2d0fff7 # v1.1.2
with:
repo: reearth/reearth-classic
version: tags/${{ github.event.inputs.name && github.event.inputs.name != 'blank' && github.event.inputs.name || github.event.inputs.new_tag }}
file: reearth-web_${{ github.event.inputs.name && github.event.inputs.name != 'blank' && github.event.inputs.name || github.event.inputs.new_tag }}.tar.gz
token: ${{ secrets.GITHUB_TOKEN }}
target: server/reearth-web.tar.gz
- name: Extract reearth/web
run: tar -xvf reearth-web.tar.gz; mv reearth-web web; ls
- name: Build and push docker image
uses: docker/build-push-action@53b7df96c91f9c12dcc8a07bcb9ccacbed38856a # v7.3.0
with:
context: server
platforms: ${{ steps.options.outputs.platforms }}
push: true
build-args: VERSION=${{ steps.options.outputs.version }}
tags: ${{ steps.options.outputs.tags }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Invoke ci-deploy-server-nightly workflow
uses: benc-uk/workflow-dispatch@31e2b3319479a63f0ab15bf800eff9e913504e26 # v1.3.2
if: github.event.inputs.name == 'nightly'
with:
workflow: deploy-server-nightly
token: ${{ steps.app-token.outputs.token }}