-
Notifications
You must be signed in to change notification settings - Fork 354
66 lines (57 loc) · 2.28 KB
/
destroy-instance.yml
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
name: Destroy instance
on:
pull_request:
types: [closed, unlabeled]
# Cancel previous runs of the same workflow and PR number or branch/tag
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
check-deploy-label:
runs-on: ubuntu-latest
outputs:
removed: ${{ steps.check.outputs.removed }}
steps:
- name: Check if "deploy" was removed
id: check
env:
GH_TOKEN: ${{ github.token }}
run: |
last_removed_label=$(
gh api "repos/$GITHUB_REPOSITORY/issues/${{ github.event.pull_request.number }}/events" \
--jq 'map(select(.event == "unlabeled"))[-1].label.name'
)
if [[ "$last_removed_label" == 'deploy' ]]; then
echo "removed=true" >> "$GITHUB_OUTPUT"
fi
destroy-instance:
needs: check-deploy-label
if: (github.event.action == 'closed' && contains(github.event.pull_request.labels.*.name, 'deploy')) || needs.check-deploy-label.outputs.removed
runs-on: ubuntu-latest
steps:
- name: 'Get latest IM tag'
id: latest-im-tag
run: |
LATEST_IM_TAG=$(git ls-remote --tags --sort='v:refname' https://github.com/dhis2-sre/im-manager | tail -1 | awk '{print $2}')
echo "LATEST_IM_TAG=$LATEST_IM_TAG" >> $GITHUB_ENV
- uses: actions/checkout@v4
with:
repository: dhis2-sre/im-manager
ref: ${{ env.LATEST_IM_TAG }}
sparse-checkout: scripts/instances
- name: Install HTTPie
run: python -m pip install httpie
- name: Destroy DHIS2 instance
working-directory: scripts/instances
env:
HTTP: https --check-status
USER_EMAIL: ${{ secrets.IM_BOT_EMAIL }}
PASSWORD: ${{ secrets.IM_BOT_PASSWORD }}
IM_HOST: 'https://api.im.dhis2.org'
INSTANCE_NAME: pr-${{ github.event.number }}
run: ./findByName.sh dev $INSTANCE_NAME && ./destroy-deployment.sh $(./findByName.sh dev $INSTANCE_NAME | jq -r '.id')
- name: Delete instance URL comment
uses: actions-cool/maintain-one-comment@v3
with:
body: "Instance deployed to https://dev.im.dhis2.org/pr-${{ github.event.pull_request.number }}"
delete: true