From d2b1d3e6a24f642de8d776e55a1fd5688e28bc53 Mon Sep 17 00:00:00 2001 From: Yousaf Nabi Date: Wed, 31 Jan 2024 16:09:59 +0000 Subject: [PATCH 1/2] ci: add workflow to update on pact-ffi-released events --- .github/workflows/update-ffi.yml | 21 +++++++++++++ script/create-pr-to-update-pact-ffi.sh | 27 +++++++++++++++++ script/dispatch-ffi-released.sh | 42 ++++++++++++++++++++++++++ 3 files changed, 90 insertions(+) create mode 100644 .github/workflows/update-ffi.yml create mode 100755 script/create-pr-to-update-pact-ffi.sh create mode 100755 script/dispatch-ffi-released.sh diff --git a/.github/workflows/update-ffi.yml b/.github/workflows/update-ffi.yml new file mode 100644 index 00000000..7119f884 --- /dev/null +++ b/.github/workflows/update-ffi.yml @@ -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 }}' diff --git a/script/create-pr-to-update-pact-ffi.sh b/script/create-pr-to-update-pact-ffi.sh new file mode 100755 index 00000000..cb8301d0 --- /dev/null +++ b/script/create-pr-to-update-pact-ffi.sh @@ -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 src/ffi/index.ts +git pull origin master + +git checkout -b ${BRANCH_NAME} + +cat src/ffi/index.ts | sed "s/export const PACT_FFI_VERSION.*/export const PACT_FFI_VERSION = '${FFI_VERSION}';/" > tmp-install +mv tmp-install src/ffi/index.ts + +git add src/ffi/index.ts +git commit -m "${TYPE}: update pact-ffi to ${STANDALONE_VERSION}" +git push --set-upstream origin ${BRANCH_NAME} + +gh pr create --title "${TYPE}: update pact-ffi to ${STANDALONE_VERSION}" --fill + +git checkout master diff --git a/script/dispatch-ffi-released.sh b/script/dispatch-ffi-released.sh new file mode 100755 index 00000000..92a3976b --- /dev/null +++ b/script/dispatch-ffi-released.sh @@ -0,0 +1,42 @@ +#!/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 + name="null" +fi + +if [ -n "$2" ]; then + version="\"${2}\"" +else + version="null" +fi + +if [ -n "$3" ]; then + increment="\"${3}\"" +else + increment="null" +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" \ No newline at end of file From 8d193856d5bba8968c1a48abe2f544bf33d6790b Mon Sep 17 00:00:00 2001 From: Yousaf Nabi Date: Wed, 31 Jan 2024 16:27:18 +0000 Subject: [PATCH 2/2] chore: ensure script takes params --- script/create-pr-to-update-pact-ffi.sh | 4 ++-- script/dispatch-ffi-released.sh | 12 ++++-------- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/script/create-pr-to-update-pact-ffi.sh b/script/create-pr-to-update-pact-ffi.sh index cb8301d0..da46a14c 100755 --- a/script/create-pr-to-update-pact-ffi.sh +++ b/script/create-pr-to-update-pact-ffi.sh @@ -19,9 +19,9 @@ cat src/ffi/index.ts | sed "s/export const PACT_FFI_VERSION.*/export const PACT_ mv tmp-install src/ffi/index.ts git add src/ffi/index.ts -git commit -m "${TYPE}: update pact-ffi to ${STANDALONE_VERSION}" +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 ${STANDALONE_VERSION}" --fill +gh pr create --title "${TYPE}: update pact-ffi to ${FFI_VERSION}" --fill git checkout master diff --git a/script/dispatch-ffi-released.sh b/script/dispatch-ffi-released.sh index 92a3976b..3ed226ed 100755 --- a/script/dispatch-ffi-released.sh +++ b/script/dispatch-ffi-released.sh @@ -9,19 +9,15 @@ if [ -n "$1" ]; then name="\"${1}\"" else - name="null" + echo "name not provided as first param" + exit 1 fi if [ -n "$2" ]; then version="\"${2}\"" else - version="null" -fi - -if [ -n "$3" ]; then - increment="\"${3}\"" -else - increment="null" + echo "name not provided as second param" + exit 1 fi repository_slug=$(git remote get-url origin | cut -d':' -f2 | sed 's/\.git//')