From deebaa30e0e0a714066109ffb8214ec0b872e28b Mon Sep 17 00:00:00 2001 From: radnov Date: Mon, 30 Oct 2023 08:49:34 +0200 Subject: [PATCH] ci: use extra job for checking if label was removed --- .github/workflows/deploy-instance.yml | 2 +- .github/workflows/destroy-instance.yml | 22 +++++++++++++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deploy-instance.yml b/.github/workflows/deploy-instance.yml index cfabc69765de..905f6a8f96b4 100644 --- a/.github/workflows/deploy-instance.yml +++ b/.github/workflows/deploy-instance.yml @@ -57,7 +57,7 @@ jobs: working-directory: scripts/instances env: EXPECTED_STATUS: Running - run: timeout 600 bash -ex -c 'while [[ "$(./status.sh dev $INSTANCE_NAME | jq -r)" != "$EXPECTED_STATUS" ]]; do echo "Instance is not $EXPECTED_STATUS yet ..."; sleep 5; done' + run: timeout 600 bash -ex -c 'until [[ "$(./status.sh dev $INSTANCE_NAME | jq -r)" == "$EXPECTED_STATUS" ]]; do echo "Instance is not $EXPECTED_STATUS yet ..."; sleep 5; done' - name: Start analytics generation run: curl -X POST -u "${{ secrets.DHIS2_USERNAME }}:${{ secrets.DHIS2_PASSWORD }}" "$INSTANCE_HOST/$INSTANCE_NAME/api/resourceTables/analytics" -d 'executeTei=true' diff --git a/.github/workflows/destroy-instance.yml b/.github/workflows/destroy-instance.yml index 938aec5e5bd6..ea1dbb5c8a94 100644 --- a/.github/workflows/destroy-instance.yml +++ b/.github/workflows/destroy-instance.yml @@ -10,8 +10,28 @@ concurrency: 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: - if: contains(github.event.pull_request.labels.*.name, 'deploy') + needs: check-deploy-label + if: github.event.action == 'closed' || needs.check-deploy-label.outputs.removed runs-on: ubuntu-latest steps: - uses: actions/checkout@v4