Skip to content

Commit

Permalink
Merge pull request #379 from pact-foundation/ci/ffi_upgrade
Browse files Browse the repository at this point in the history
ci: add workflow to update on pact-ffi-released events
  • Loading branch information
YOU54F committed Feb 1, 2024
2 parents 7acfdce + 3b310af commit c1f2dfe
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 0 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/update-ffi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Update Pact FFI Library

on:
repository_dispatch:
types:
- pact-ffi-released

jobs:
update:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- run: |
git config --global user.email "${GITHUB_ACTOR}@users.noreply.github.com"
git config --global user.name "${GITHUB_ACTOR}"
git config pull.ff only
- run: script/create-pr-to-update-pact-ffi.sh ${{ github.event.client_payload.version }}
env:
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'
27 changes: 27 additions & 0 deletions scripts/create-pr-to-update-pact-ffi.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/sh

set -e

: "${1?Please supply the pact-ffi version to upgrade to}"

FFI_VERSION=$1
TYPE=${2:-fix}
DASHERISED_VERSION=$(echo "${FFI_VERSION}" | sed 's/\./\-/g')
BRANCH_NAME="chore/upgrade-to-pact-ffi-${DASHERISED_VERSION}"

git checkout master
git checkout installer/installer.go
git pull origin master

git checkout -b ${BRANCH_NAME}

cat installer/installer.go | sed "s/version:.*/version: \"${FFI_VERSION}\",/" > tmp-install
mv tmp-install installer/installer.go

git add installer/installer.go
git commit -m "${TYPE}: update pact-ffi to ${FFI_VERSION}"
git push --set-upstream origin ${BRANCH_NAME}

gh pr create --title "${TYPE}: update pact-ffi to ${FFI_VERSION}" --fill

git checkout master
38 changes: 38 additions & 0 deletions scripts/dispatch-ffi-released.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/sh

# Script to trigger an update of the pact ffi from pact-foundation/pact-reference to listening repos
# Requires a Github API token with repo scope stored in the
# environment variable GITHUB_ACCESS_TOKEN_FOR_PF_RELEASES

: "${GITHUB_ACCESS_TOKEN_FOR_PF_RELEASES:?Please set environment variable GITHUB_ACCESS_TOKEN_FOR_PF_RELEASES}"

if [ -n "$1" ]; then
name="\"${1}\""
else
echo "name not provided as first param"
exit 1
fi

if [ -n "$2" ]; then
version="\"${2}\""
else
echo "name not provided as second param"
exit 1
fi

repository_slug=$(git remote get-url origin | cut -d':' -f2 | sed 's/\.git//')

output=$(curl -v https://api.github.com/repos/${repository_slug}/dispatches \
-H 'Accept: application/vnd.github.everest-preview+json' \
-H "Authorization: Bearer $GITHUB_ACCESS_TOKEN_FOR_PF_RELEASES" \
-d "{\"event_type\": \"pact-ffi-released\", \"client_payload\": {\"name\": ${name}, \"version\" : ${version}}}" 2>&1)

if ! echo "${output}" | grep "HTTP\/.* 204" > /dev/null; then
echo "$output" | sed "s/${GITHUB_ACCESS_TOKEN_FOR_PF_RELEASES}/********/g"
echo "Failed to trigger update"
exit 1
else
echo "Update workflow triggered"
fi

echo "See https://github.com/${repository_slug}/actions?query=workflow%3A%22Update+Pact+FFI+Library%22"

0 comments on commit c1f2dfe

Please sign in to comment.