Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: add workflow to update on pact-ffi-released events #379

Merged
merged 1 commit into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
Loading