Skip to content

Commit 6e7b9a5

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

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

.github/workflows/ovh.yaml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,12 @@ on:
2424
required: true
2525
OVH_PASSWORD:
2626
required: true
27+
MIXXX_WEBSITE_ENV_CLEANUP_PAT:
28+
required: true
2729

2830
jobs:
2931
apply:
32+
name: ${{ format('{0} environment "{1}"', inputs.action == 'teardown' && 'Tearing down' || 'Deploying', inputs.environment_name) }}
3033
runs-on: ubuntu-latest
3134
concurrency:
3235
group: website-ovh-${{ inputs.target }}
@@ -128,3 +131,30 @@ jobs:
128131
mkdir empty
129132
ssh-keyscan "${OVH_HOSTNAME}" >> "${HOME}/.ssh/known_hosts"
130133
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"
134+
135+
- name: Deleting environment
136+
if: ${{ inputs.action == 'teardown' && inputs.target != 'www' }}
137+
env:
138+
ENVIRONMENT_NAME: ${{ inputs.environment_name }}
139+
uses: actions/github-script@v9
140+
with:
141+
github-token: ${{ secrets.MIXXX_WEBSITE_ENV_CLEANUP_PAT }}
142+
script: |
143+
const environment = process.env.ENVIRONMENT_NAME;
144+
145+
try {
146+
147+
await github.rest.repos.deleteAnEnvironment({
148+
owner: context.repo.owner,
149+
repo: context.repo.repo,
150+
environment_name: environment,
151+
});
152+
153+
console.log(`Deleted environment '${environment}'`);
154+
} catch (err) {
155+
if (err.status === 404) {
156+
console.log(`Environment '${environment}' does not exist.`);
157+
} else {
158+
throw err;
159+
}
160+
}

0 commit comments

Comments
 (0)