Repository navigation
73 lines (68 loc) · 2.82 KB
/
Copy pathdeploy-dev.yml
File metadata and controls
73 lines (68 loc) · 2.82 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
name: Auto-deploy dev
on:
workflow_run:
workflows: [CI]
types: [completed]
branches: [main]
permissions:
actions: read
deployments: write
jobs:
publish:
name: Request dev deployment
runs-on: ubuntu-latest
if: >-
github.repository == 'blkerby/MapRandomizer' &&
github.event.workflow_run.conclusion == 'success' &&
github.event.workflow_run.event == 'push' &&
github.event.workflow_run.head_branch == 'main'
steps:
- name: Download image metadata from the triggering build attempt
uses: actions/download-artifact@v8
with:
name: image-metadata-${{ github.event.workflow_run.run_attempt }}
path: image-metadata
run-id: ${{ github.event.workflow_run.id }}
github-token: ${{ github.token }}
- name: Publish deployment request
uses: actions/github-script@v8
with:
script: |
const fs = require('node:fs/promises');
const run = context.payload.workflow_run;
const metadata = JSON.parse(await fs.readFile('image-metadata/image-metadata.json', 'utf8'));
const deployConfig = metadata.deploy_configs['rtx/dev'];
if (deployConfig === undefined) {
throw new Error('Build metadata is missing .github/deploy/rtx/dev.json');
}
// Rerunning this publisher creates a new request, including to retry a failed rollout.
const response = await github.rest.repos.createDeployment({
...context.repo,
ref: run.head_sha,
environment: 'dev',
task: 'deploy:image',
auto_merge: false,
required_contexts: [],
production_environment: false,
transient_environment: false,
description: `CI run ${run.id}, attempt ${run.run_attempt}`,
payload: {
digest: metadata.digest,
deploy_config: deployConfig,
build_run_id: run.id,
build_run_attempt: run.run_attempt
}
});
if (response.status !== 201) {
throw new Error(`Expected a deployment request, received HTTP ${response.status}`);
}
const deployment = response.data;
await core.summary
.addRaw('## Dev deployment request\n\n')
.addRaw([
`Image digest: ${metadata.digest}`,
`Commit: [${run.head_sha}](${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/commit/${run.head_sha})`,
`Build: [run ${run.id}, attempt ${run.run_attempt}](${run.html_url}/attempts/${run.run_attempt})`,
`Deployment: [${deployment.id}](${deployment.url})`
].map(item => `- ${item}`).join('\n') + '\n')
.write();