-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add git workflow to delete old branches in pactflow
- Loading branch information
Showing
2 changed files
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
name: Delete application branch in Pactflow | ||
|
||
on: | ||
delete: | ||
branches: | ||
- "*" | ||
|
||
jobs: | ||
delete-branch-in-pactflow: | ||
name: delete | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
# Requires Ruby to encode the URL path correctly - could use any other scripting language here | ||
- uses: ruby/setup-ruby@v1 | ||
|
||
- name: Delete branch ${GIT_BRANCH} for application ${PACTICIPANT} in Pactflow | ||
run: script/ci/delete-branch-in-pactflow.sh | ||
env: | ||
GIT_BRANCH: ${{ github.event.ref }} | ||
PACTICIPANT: "Pact Broker Client" | ||
PACT_BROKER_TOKEN: ${{ secrets.PACT_BROKER_TOKEN_PACT_FOUNDATION }} | ||
PACT_BROKER_BASE_URL=https://pact-foundation.pactflow.io |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#!/bin/bash | ||
|
||
set -Eeuo pipefail | ||
|
||
echo "Deleting branch ${GIT_BRANCH} for ${PACTICIPANT} in Pactflow..." | ||
ENCODED_GIT_BRANCH=$(echo "$GIT_BRANCH" | ruby -e "require 'erb'; puts ERB::Util.url_encode(ARGF.read.chomp)") | ||
ENCODED_PACTICIPANT=$(echo "$PACTICIPANT" | ruby -e "require 'erb'; puts ERB::Util.url_encode(ARGF.read.chomp)") | ||
BRANCH_URL="${PACT_BROKER_BASE_URL}/pacticipants/${ENCODED_PACTICIPANT}/branches/${ENCODED_GIT_BRANCH}" | ||
|
||
output_file=$(mktemp) | ||
|
||
status=$(curl -v -X DELETE "${BRANCH_URL}" -H "Authorization: Bearer ${PACT_BROKER_TOKEN}" 2>&1 | tee "${output_file}" | awk '/^< HTTP/{print $3}') | ||
|
||
if [ "$status" = "404" ]; then | ||
echo "Branch ${GIT_BRANCH} for ${PACTICIPANT} does not exist in Pactflow" | ||
elif [ $status -ge 400 ]; then | ||
cat "${output_file}" | ||
echo "Error deleting branch in Pactflow" | ||
exit 1 | ||
else | ||
echo "Deleted branch ${GIT_BRANCH} for ${PACTICIPANT} in Pactflow" | ||
fi |