Skip to content

Commit 24c295a

Browse files
authored
bobheadxi/deployments@v1 (#40)
Notable changes: - CHANGED: no_override is now override, and the default behaviour is override: true in step: finish (step: start behaviour remains unchanged, but you can now set override: true on it now as well). - CHANGED: log_args is now debug, but does the same thing as before. - CHANGED: env is now always required. You can use env: ${{ steps.deployment.outputs.env }} to avoid repeating your env configuration. - REMOVED: auto_inactive - use override instead. - REMOVED: transient - all deployments created by this action are transient by default, with removals handled by override or step: deactivate. - ADDED: step: delete-env deletes an environment entirely.
1 parent e97c105 commit 24c295a

File tree

20 files changed

+789
-297
lines changed

20 files changed

+789
-297
lines changed

.github/workflows/cleanup.yaml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: cleanup
2+
3+
on:
4+
pull_request:
5+
types: [ closed ]
6+
7+
jobs:
8+
test:
9+
runs-on: ubuntu-latest
10+
strategy:
11+
matrix:
12+
scenario: [ 'success', 'failure' ]
13+
steps:
14+
- uses: actions/checkout@v2
15+
- uses: actions/setup-node@v2
16+
with:
17+
node-version: '12'
18+
19+
# Dependencies
20+
# https://docs.github.com/en/actions/guides/caching-dependencies-to-speed-up-workflows#example-using-the-cache-action
21+
- name: Cache node modules
22+
uses: actions/cache@v2
23+
env:
24+
cache-name: cache-node-modules
25+
with:
26+
path: ~/.npm # npm cache files are stored in `~/.npm` on Linux/macOS
27+
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
28+
restore-keys: |
29+
${{ runner.os }}-build-${{ env.cache-name }}-
30+
${{ runner.os }}-build-
31+
${{ runner.os }}-
32+
- run: npm install
33+
- run: npm run build
34+
35+
- name: extract branch name
36+
id: get_branch
37+
shell: bash
38+
env:
39+
PR_HEAD: ${{ github.head_ref }}
40+
run: echo "##[set-output name=branch;]$(echo ${PR_HEAD#refs/heads/} | tr / -)"
41+
42+
- name: delete environment
43+
uses: ./
44+
with:
45+
step: deactivate-env
46+
token: ${{ secrets.GITHUB_TOKEN }}
47+
env: integration-test-${{ steps.get_branch.outputs.branch }}-${{ matrix.scenario }}
48+
debug: true

.github/workflows/pipeline.yaml

Lines changed: 123 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
name: pipeline
22

3-
on: [push]
3+
on: [ push ]
44

55
jobs:
6-
build:
6+
checks:
77
runs-on: ubuntu-latest
88
steps:
99
# Environment
@@ -30,3 +30,124 @@ jobs:
3030
# Checks
3131
- run: npm run prettier:check
3232
- run: npm run build:check
33+
34+
integration-tests:
35+
runs-on: ubuntu-latest
36+
needs: checks
37+
strategy:
38+
matrix:
39+
scenario: [ 'success', 'failure' ]
40+
include:
41+
- scenario: 'success'
42+
exit_code: 0
43+
- scenario: 'failure'
44+
exit_code: 1
45+
fail-fast: false
46+
steps:
47+
- uses: actions/checkout@v2
48+
- uses: actions/setup-node@v2
49+
with:
50+
node-version: '12'
51+
52+
# Dependencies
53+
# https://docs.github.com/en/actions/guides/caching-dependencies-to-speed-up-workflows#example-using-the-cache-action
54+
- name: Cache node modules
55+
uses: actions/cache@v2
56+
env:
57+
cache-name: cache-node-modules
58+
with:
59+
path: ~/.npm # npm cache files are stored in `~/.npm` on Linux/macOS
60+
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
61+
restore-keys: |
62+
${{ runner.os }}-build-${{ env.cache-name }}-
63+
${{ runner.os }}-build-
64+
${{ runner.os }}-
65+
- run: npm install
66+
- run: npm run build
67+
68+
- name: extract branch name
69+
id: get_branch
70+
shell: bash
71+
run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/} | tr / -)"
72+
73+
- name: start deployment
74+
uses: ./
75+
id: deployment
76+
with:
77+
step: start
78+
token: ${{ secrets.GITHUB_TOKEN }}
79+
env: integration-test-${{ steps.get_branch.outputs.branch }}-${{ matrix.scenario }}
80+
desc: 'Deployment starting!'
81+
debug: true
82+
83+
- name: assert deployment in progress
84+
uses: actions/github-script@v6
85+
env:
86+
deployment_id: ${{ steps.deployment.outputs.deployment_id }}
87+
status_id: ${{ steps.deployment.outputs.status_id }}
88+
with:
89+
script: |
90+
const { deployment_id, status_id } = process.env;
91+
if (!deployment_id) {
92+
throw new Error("deployment_id not set");
93+
}
94+
if (!status_id) {
95+
throw new Error("status_id not set");
96+
}
97+
const res = await github.rest.repos.getDeploymentStatus({
98+
owner: "bobheadxi",
99+
repo: "deployments",
100+
deployment_id: parseInt(deployment_id, 10),
101+
status_id: parseInt(status_id, 10),
102+
});
103+
console.log(res)
104+
if (res.data.state !== "in_progress") {
105+
throw new Error(`unexpected status ${res.data.state}`);
106+
}
107+
108+
- name: set deployment status to ${{ matrix.scenario }}
109+
uses: ./
110+
id: finish
111+
with:
112+
step: finish
113+
token: ${{ secrets.GITHUB_TOKEN }}
114+
status: ${{ matrix.scenario }}
115+
deployment_id: ${{ steps.deployment.outputs.deployment_id }}
116+
env: ${{ steps.deployment.outputs.env }}
117+
desc: 'Deployment complete'
118+
debug: true
119+
120+
- name: assert deployment complete
121+
uses: actions/github-script@v6
122+
env:
123+
deployment_id: ${{ steps.deployment.outputs.deployment_id }}
124+
status_id: ${{ steps.finish.outputs.status_id }}
125+
expected_state: ${{ matrix.scenario }}
126+
with:
127+
script: |
128+
const { deployment_id, status_id, expected_state } = process.env;
129+
if (!deployment_id) {
130+
throw new Error("deployment_id not set");
131+
}
132+
if (!status_id) {
133+
throw new Error("status_id not set");
134+
}
135+
const res = await github.rest.repos.getDeploymentStatus({
136+
owner: "bobheadxi",
137+
repo: "deployments",
138+
deployment_id: parseInt(deployment_id, 10),
139+
status_id: parseInt(status_id, 10),
140+
});
141+
console.log(res)
142+
if (res.data.state !== expected_state) {
143+
throw new Error(`unexpected status ${res.data.state}`);
144+
}
145+
146+
- name: mark environment as deactivated
147+
uses: ./
148+
with:
149+
step: deactivate-env
150+
token: ${{ secrets.GITHUB_TOKEN }}
151+
env: ${{ steps.deployment.outputs.env }}
152+
desc: Environment was pruned
153+
debug: true

.github/workflows/publish_v1.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: publish@v1
2+
3+
on:
4+
push:
5+
tags: [ 'v1.*' ]
6+
7+
jobs:
8+
publish:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: checkout
12+
uses: actions/checkout@v2
13+
- name: update tag
14+
run: |
15+
git config --global user.email "${GITHUB_ACTOR}@users.noreply.github.com"
16+
git config --global user.name "${GITHUB_ACTOR}"
17+
git tag -fa v1 -m "update v1 tag"
18+
git push origin v1 --force

0 commit comments

Comments
 (0)