-
Notifications
You must be signed in to change notification settings - Fork 1
195 lines (194 loc) · 7.21 KB
/
build.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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
name: build
on:
workflow_run:
workflows: [ci]
types: ["completed"]
branches: [main, release]
concurrency:
group: ${{ github.workflow }}-${{ github.event.workflow_run.head_branch }}
cancel-in-progress: true
jobs:
info:
name: Collect information
runs-on: ubuntu-latest
if: github.event.workflow_run.conclusion != 'failure' && github.event.repository.full_name == 'reearth/reearth-marketplace' && (github.event.workflow_run.head_branch == 'release' || !startsWith(github.event.head_commit.message, 'v'))
outputs:
sha_short: ${{ steps.info.outputs.sha_short }}
new_tag: ${{ steps.info.outputs.new_tag}}
new_tag_short: ${{ steps.info.outputs.new_tag_short }}
name: ${{ steps.info.outputs.name }}
steps:
- name: checkout
uses: actions/checkout@v3
with:
ref: ${{ github.event.workflow_run.head_sha }}
- name: fetch tags
run: git fetch --prune --unshallow --tags
- name: Get info
id: info
env:
BRANCH: ${{ github.event.workflow_run.head_branch }}
run: |
echo "::set-output name=sha_short::$(git rev-parse --short HEAD)"
if [[ "$BRANCH" = "release" ]]; then
TAG=$(git tag --points-at HEAD)
if [[ ! -z "$TAG" ]]; then
echo "::set-output name=new_tag::$TAG"
echo "::set-output name=new_tag_short::${TAG#v}"
else
echo "::set-output name=name::rc"
fi
else
echo "::set-output name=name::nightly"
fi
- name: Show info
env:
SHA_SHORT: ${{ steps.info.outputs.sha_short }}
NEW_TAG: ${{ steps.info.outputs.new_tag }}
NEW_TAG_SHORT: ${{ steps.info.outputs.new_tag_short }}
NAME: ${{ steps.info.outputs.name }}
run: echo "sha_short=$SHA_SHORT, new_tag=$NEW_TAG, new_tag_short=$NEW_TAG_SHORT, name=$NAME"
build:
name: Build and release nightly/rc
runs-on: ubuntu-latest
needs:
- info
if: needs.info.outputs.name || needs.info.outputs.new_tag
env:
# ARTIFACTS_SERVER: server/dist #TODO: fix here
ARTIFACTS_WEB: reearth-marketplace-web_${{ needs.info.outputs.name }}.tar.gz
steps:
- uses: actions/create-github-app-token@v1
id: app-token
with:
app-id: ${{ vars.GH_APP_ID }}
private-key: ${{ secrets.GH_APP_PRIVATE_KEY }}
- name: get latest web artifact
uses: dawidd6/action-download-artifact@v2
with:
github_token: ${{ steps.app-token.outputs.token }}
workflow: ci.yml
workflow_conclusion: success
branch: ${{ github.event.workflow_run.head_branch }}
name: reearth-marketplace-web
check_artifacts: true
search_artifacts: true
- name: rename artifact
run: mv reearth-marketplace-web.tar.gz $ARTIFACTS_WEB
- name: Release nightly/rc
if: needs.info.outputs.name
uses: ncipollo/release-action@v1
with:
allowUpdates: true
artifactErrorsFailBuild : true
artifacts: ${{ env.ARTIFACTS_WEB }}
# artifacts: ${{ env.ARTIFACTS_SERVER }},${{ env.ARTIFACTS_WEB }}
commit: ${{ github.sha }}
name: ${{ needs.info.outputs.name }}
tag: ${{ needs.info.outputs.name }}
body: ${{ github.sha }}
prerelease: true
# This is for stable release with version tags
- name: Dowload latest changelog
if: needs.info.outputs.new_tag
uses: dawidd6/action-download-artifact@v2
with:
workflow: release.yml
name: changelog-${{ needs.info.outputs.new_tag }}
- name: Create GitHub release
if: needs.info.outputs.new_tag
uses: ncipollo/release-action@v1
with:
#TODO: サーバー側のartifactを修正
artifacts: ${{ env.ARTIFACTS_WEB }}
commit: ${{ github.sha }}
name: ${{ needs.info.outputs.new_tag }}
tag: ${{ needs.info.outputs.new_tag }}
bodyFile: CHANGELOG_latest.md
docker:
name: Build and push Docker image
runs-on: ubuntu-latest
needs:
- info
if: needs.info.outputs.name || needs.info.outputs.new_tag
env:
IMAGE_NAME: reearth/reearth-marketplace
steps:
- name: Checkout
uses: actions/checkout@v3
- uses: actions/create-github-app-token@v1
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@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to DockerHub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Get options
id: options
env:
TAG: ${{ needs.info.outputs.new_tag_short }}
NAME: ${{ needs.info.outputs.name }}
SHA: ${{ needs.info.outputs.sha_short }}
run: |
if [[ -n $TAG ]]; then
PLATFORMS=linux/amd64
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: Download web arfiacts
uses: dawidd6/action-download-artifact@v2
with:
github_token: ${{ steps.app-token.outputs.token }}
workflow: ci.yml
workflow_conclusion: success
branch: ${{ github.event.workflow_run.head_branch }}
name: reearth-marketplace-web
check_artifacts: true
- name: Extract
run: tar -xvf reearth-marketplace-web.tar.gz && mv reearth-marketplace-web server/web
- name: Build and load docker image
uses: docker/build-push-action@v3
with:
context: ./server
platforms: ${{ steps.options.outputs.platforms }}
load: true
build-args: VERSION=${{ steps.options.outputs.version }}
tags: ${{ steps.options.outputs.tags }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Push docker images
run: docker push ${{ steps.options.outputs.tags }}
- name: Make dir
run: mkdir reearth
- name: Save docker image
run: docker save ${{ steps.options.outputs.tags }} | gzip > reearth-marketplace.tar.gz
- name: Save imaged to artifact
uses: actions/upload-artifact@v4
# env:
# TAG: ${{ needs.info.outputs.tag_short }}
# NAME: ${{ needs.info.outputs.name }}
with:
name: reearth-marketplace
# name: '[ -n $TAG ] && echo reearth-marketplace_$TAG || echo reearth-marketplace_$'
path: reearth-marketplace.tar.gz
if-no-files-found: error
# TODO: invoke deploy test env if name == "nightly" with workflow_call event