Repository navigation
179 lines (158 loc) · 7.12 KB
/
Copy pathrelease.yml
File metadata and controls
179 lines (158 loc) · 7.12 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
172
173
174
175
176
177
178
179
# Releases backoffice with each PlaceOS platform release. See docs/releases.md.
#
# The release ships the backoffice commit that the interfaces/backoffice
# submodule of PlaceOS/PlaceOS pins for that version. The workflow tags it
# v<version>, tests it, builds it and publishes it to build/prod. PlaceOS
# installs load backoffice from build/prod.
name: RELEASE
on:
# Sent by the "Tag and release" job of build.yml in PlaceOS/PlaceOS, with
# the payload { "version": "2.2611.6" }
repository_dispatch:
types: [placeos-release]
# To retry a release, or to roll back to an earlier version
workflow_dispatch:
inputs:
version:
description: 'PlaceOS version, for example 2.2611.6'
required: true
type: string
permissions:
contents: write
# One release at a time. A release that starts during a release waits.
concurrency:
group: release
cancel-in-progress: false
jobs:
resolve:
runs-on: ubuntu-latest
timeout-minutes: 2
outputs:
sha: ${{ steps.resolve.outputs.sha }}
tag: ${{ steps.resolve.outputs.tag }}
steps:
- name: Find the backoffice commit that the PlaceOS version pins
id: resolve
env:
GH_TOKEN: ${{ github.token }}
VERSION: ${{ github.event.client_payload.version || inputs.version }}
run: |
if [[ ! "$VERSION" =~ ^[0-9]+\.[0-9]{4}\.[0-9]+$ ]]; then
echo "::error::The version is not a PlaceOS release version, for example 2.2611.6"
exit 1
fi
sha="$(gh api "repos/PlaceOS/PlaceOS/contents/interfaces/backoffice?ref=${VERSION}" --jq .sha)"
if [[ ! "$sha" =~ ^[0-9a-f]{40}$ ]]; then
echo "::error::PlaceOS ${VERSION} does not pin a backoffice commit"
exit 1
fi
# Release only reviewed code. The cache scope of develop is
# shared, so a commit from a fork must not run here.
status="$(gh api "repos/${GITHUB_REPOSITORY}/compare/${sha}...develop" --jq .status)"
if [[ "$status" != "ahead" && "$status" != "identical" ]]; then
echo "::error::${sha} is not on develop"
exit 1
fi
# A retry can use the tag again. A tag on a different commit stops the release.
tag="v${VERSION}"
tagged="$(git ls-remote "https://github.com/${GITHUB_REPOSITORY}" "refs/tags/${tag}" | cut -f1)"
if [[ -n "$tagged" && "$tagged" != "$sha" ]]; then
echo "::error::${tag} is on ${tagged}. PlaceOS ${VERSION} pins ${sha}"
exit 1
fi
echo "Releasing ${sha} as ${tag}"
echo "sha=${sha}" >> "$GITHUB_OUTPUT"
echo "tag=${tag}" >> "$GITHUB_OUTPUT"
test:
needs: [resolve]
permissions:
contents: read
uses: ./.github/workflows/test.yml
with:
ref: ${{ needs.resolve.outputs.sha }}
build:
needs: [resolve]
permissions:
contents: read
uses: ./.github/workflows/build-app.yml
with:
ref: ${{ needs.resolve.outputs.sha }}
configuration: production
tag: ${{ needs.resolve.outputs.tag }}
secrets: inherit
# Publish only after the tests pass
publish:
needs: [resolve, test, build]
runs-on: ubuntu-latest
timeout-minutes: 3
env:
SHA: ${{ needs.resolve.outputs.sha }}
TAG: ${{ needs.resolve.outputs.tag }}
steps:
- uses: actions/checkout@v6
with:
ref: ${{ needs.resolve.outputs.sha }}
- name: Download build artifact
uses: actions/download-artifact@v4
with:
name: build-output
path: dist/backoffice/browser
# Vercel reads vercel.json from the pushed commit. Build branches
# hold only the built files, so add one that turns off deployments.
- name: Turn off Vercel deployments for the build branch
run: |
echo '{ "git": { "deploymentEnabled": false } }' > dist/backoffice/browser/vercel.json
- name: Deploy the application
uses: MrYuion/git-publish-subdir-action@develop
env:
REPO: self
BRANCH: build/prod
FOLDER: dist/backoffice/browser
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
MESSAGE: 'build(backoffice): ${{ needs.resolve.outputs.tag }} from {sha}'
# Pushes nothing when a retry already pushed the tag
- name: Push the release tag
run: git push origin "${SHA}:refs/tags/${TAG}"
- name: Update Pipeline Chat Status
uses: fjogeleit/http-request-action@master
continue-on-error: true
with:
url: ${{ secrets.STATUS_URL }}
data: '{ "name": "${{ github.repository }}", "commit": "${{ needs.resolve.outputs.sha }}", "pipeline_name": "backoffice", "branch": "build/prod", "status": "${{ job.status }}", "url": "https://github.com/${{ github.repository }}/runs/${{ github.run_id }}" }'
if: ${{ always() }}
# A separate job, so that a failed push to develop does not show as a failed
# deploy. Re-run this job alone to retry it.
changelog:
needs: [resolve, publish]
runs-on: ubuntu-latest
timeout-minutes: 2
steps:
- uses: actions/checkout@v6
with:
ref: develop
- name: Download build artifact
uses: actions/download-artifact@v4
with:
name: build-output
path: ${{ runner.temp }}/build
- name: Commit the changelog to develop
env:
TAG: ${{ needs.resolve.outputs.tag }}
run: |
# A rollback has an older changelog. Keep the newer one.
newest="$(git ls-remote --tags origin | cut -f2 | sed 's|^refs/tags/||' \
| grep -E '^v[0-9]+\.[0-9]{4}\.[0-9]+$' | sort -V | tail -1)"
if [[ "$newest" != "$TAG" ]]; then
echo "${newest} is newer than ${TAG}. CHANGELOG.md stays the same."
exit 0
fi
cp "${RUNNER_TEMP}/build/CHANGELOG.md" CHANGELOG.md
git add CHANGELOG.md
if git diff --cached --quiet; then
echo "CHANGELOG.md is already up to date."
exit 0
fi
git config user.name 'github-actions[bot]'
git config user.email 'github-actions[bot]@users.noreply.github.com'
git commit -m "docs(changelog): update for ${TAG}"
git push origin HEAD:develop