Skip to content

Commit 5b858d7

Browse files
committed
chore(OVH): delete environment when it gets tear down
1 parent 190ce21 commit 5b858d7

2 files changed

Lines changed: 31 additions & 0 deletions

File tree

.github/workflows/deploy.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ jobs:
2020
secrets: inherit
2121

2222
cleanup:
23+
permissions:
24+
contents: read
25+
deployments: write
26+
actions: write
2327
if: |
2428
github.event_name == 'pull_request_target' && (github.event.action == 'closed' || contains(github.event.pull_request.labels.*.name, 'stale'))
2529
uses: ./.github/workflows/ovh.yaml

.github/workflows/ovh.yaml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ on:
2727

2828
jobs:
2929
apply:
30+
name: ${{ format('{0} environment "{1}"', inputs.action == 'teardown' && 'Tearing down' || 'Deploying', inputs.environment_name) }}
3031
runs-on: ubuntu-latest
3132
concurrency:
3233
group: website-ovh-${{ inputs.target }}
@@ -128,3 +129,29 @@ jobs:
128129
mkdir empty
129130
ssh-keyscan "${OVH_HOSTNAME}" >> "${HOME}/.ssh/known_hosts"
130131
lftp --env-password -u ${OVH_USERNAME} sftp://${OVH_HOSTNAME} -e "set sftp:connect-program \"ssh -o Compression=no\"; set mirror:parallel-transfer-count 16; set mirror:parallel-directories yes; mirror -vv --delete -P 16 -R ./empty /home/${OVH_USERNAME}/${TARGET}; rmdir /home/${OVH_USERNAME}/${TARGET}; quit"
132+
133+
- name: Deleting environment
134+
if: ${{ inputs.action == 'teardown' && inputs.target != 'www' }}
135+
env:
136+
ENVIRONMENT_NAME: ${{ inputs.environment_name }}
137+
uses: actions/github-script@v9
138+
with:
139+
script: |
140+
const environment = process.env.ENVIRONMENT_NAME;
141+
142+
try {
143+
144+
await github.rest.repos.deleteAnEnvironment({
145+
owner: context.repo.owner,
146+
repo: context.repo.repo,
147+
environment_name: environment,
148+
});
149+
150+
console.log(`Deleted environment '${environment}'`);
151+
} catch (err) {
152+
if (err.status === 404) {
153+
console.log(`Environment '${environment}' does not exist.`);
154+
} else {
155+
throw err;
156+
}
157+
}

0 commit comments

Comments
 (0)