-
Notifications
You must be signed in to change notification settings - Fork 2
141 lines (119 loc) · 5.12 KB
/
Copy pathdeploy.yml
File metadata and controls
141 lines (119 loc) · 5.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
name: Deploy
env:
registry: "ghcr.io"
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
SLACK_CHANNEL_ID: ${{ secrets.SLACK_CHANNEL_ID }}
on:
workflow_run:
workflows: ["Version Bump"]
types:
- completed
workflow_dispatch:
concurrency:
group: deploy-${{ github.ref }}
cancel-in-progress: false
permissions:
actions: read
contents: read
packages: write
jobs:
verify-version-job:
if: ${{ github.event.repository.fork == false && (github.event_name == 'workflow_dispatch' || github.event.workflow_run.conclusion == 'success') }}
runs-on: ubuntu-latest
outputs:
should_deploy: ${{ steps.check-version.outputs.should_deploy }}
steps:
- name: verify version job succeeded
id: check-version
uses: actions/github-script@v9
with:
script: |
if (context.eventName === "workflow_dispatch") {
core.setOutput("should_deploy", "true");
return;
}
const runId = context.payload.workflow_run?.id;
if (!runId) {
core.info("No upstream workflow run id found. Skipping deploy.");
core.setOutput("should_deploy", "false");
return;
}
const jobs = await github.paginate(github.rest.actions.listJobsForWorkflowRun, {
owner: context.repo.owner,
repo: context.repo.repo,
run_id: runId,
per_page: 100,
});
const versionJob = jobs.find((job) => job.name === "version");
const shouldDeploy = Boolean(versionJob && versionJob.conclusion === "success");
if (!shouldDeploy) {
core.info("Version Bump 'version' job did not succeed; skipping deploy.");
}
core.setOutput("should_deploy", shouldDeploy ? "true" : "false");
docker:
needs: verify-version-job
if: ${{ needs.verify-version-job.outputs.should_deploy == 'true' }}
runs-on: ubuntu-latest
steps:
- name: checkout repository
uses: actions/checkout@v6
- name: send slack start message
id: slack-start
uses: ./.github/actions/slack-run-start
with:
message_prefix: Deployment running
- name: setup node
uses: actions/setup-node@v6
with:
node-version: 20
cache: npm
- name: install dependencies
run: npm ci
- name: set build timestamp
id: build-time
run: echo "value=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> "$GITHUB_OUTPUT"
- name: get backend version
id: backend-version
uses: martinbeentjes/npm-get-version-action@v1.1.0
with:
path: ./
- name: print backend version
run: echo "building server image with version ${{ steps.backend-version.outputs.current-version }}"
- name: set up qemu
uses: docker/setup-qemu-action@v4
- name: set up docker buildx
id: buildx
uses: docker/setup-buildx-action@v4
with:
buildkitd-flags: --debug
- name: login to ghcr
uses: docker/login-action@v4
with:
registry: ${{ env.registry }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
logout: false
- name: build and push server image
uses: docker/build-push-action@v7
with:
context: "."
file: ./src/server/Dockerfile
platforms: linux/amd64
push: true
tags: |
${{ env.registry }}/${{ github.repository_owner }}/bug:${{ steps.backend-version.outputs.current-version }}
${{ env.registry }}/${{ github.repository_owner }}/bug:latest
labels: |
author=${{ github.actor }}
version=${{ steps.backend-version.outputs.current-version }}
org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }}
uk.co.bbc.bug.build.timestamp=${{ steps.build-time.outputs.value }}
uk.co.bbc.bug.build.number=${{ github.run_number }}
uk.co.bbc.bug.build.commit=${{ github.sha }}
- name: update slack message
if: ${{ always() && steps.slack-start.outputs.ts != '' }}
uses: ./.github/actions/slack-run-finish
with:
ts: ${{ steps.slack-start.outputs.ts }}
status: ${{ job.status }}
message_prefix: Deployment