Skip to content

Commit c1f2dfe

Browse files
authored
Merge pull request #379 from pact-foundation/ci/ffi_upgrade
ci: add workflow to update on pact-ffi-released events
2 parents 7acfdce + 3b310af commit c1f2dfe

File tree

3 files changed

+86
-0
lines changed

3 files changed

+86
-0
lines changed

.github/workflows/update-ffi.yml

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: Update Pact FFI Library
2+
3+
on:
4+
repository_dispatch:
5+
types:
6+
- pact-ffi-released
7+
8+
jobs:
9+
update:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v2
13+
14+
- run: |
15+
git config --global user.email "${GITHUB_ACTOR}@users.noreply.github.com"
16+
git config --global user.name "${GITHUB_ACTOR}"
17+
git config pull.ff only
18+
19+
- run: script/create-pr-to-update-pact-ffi.sh ${{ github.event.client_payload.version }}
20+
env:
21+
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'
+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/bin/sh
2+
3+
set -e
4+
5+
: "${1?Please supply the pact-ffi version to upgrade to}"
6+
7+
FFI_VERSION=$1
8+
TYPE=${2:-fix}
9+
DASHERISED_VERSION=$(echo "${FFI_VERSION}" | sed 's/\./\-/g')
10+
BRANCH_NAME="chore/upgrade-to-pact-ffi-${DASHERISED_VERSION}"
11+
12+
git checkout master
13+
git checkout installer/installer.go
14+
git pull origin master
15+
16+
git checkout -b ${BRANCH_NAME}
17+
18+
cat installer/installer.go | sed "s/version:.*/version: \"${FFI_VERSION}\",/" > tmp-install
19+
mv tmp-install installer/installer.go
20+
21+
git add installer/installer.go
22+
git commit -m "${TYPE}: update pact-ffi to ${FFI_VERSION}"
23+
git push --set-upstream origin ${BRANCH_NAME}
24+
25+
gh pr create --title "${TYPE}: update pact-ffi to ${FFI_VERSION}" --fill
26+
27+
git checkout master

scripts/dispatch-ffi-released.sh

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/bin/sh
2+
3+
# Script to trigger an update of the pact ffi from pact-foundation/pact-reference to listening repos
4+
# Requires a Github API token with repo scope stored in the
5+
# environment variable GITHUB_ACCESS_TOKEN_FOR_PF_RELEASES
6+
7+
: "${GITHUB_ACCESS_TOKEN_FOR_PF_RELEASES:?Please set environment variable GITHUB_ACCESS_TOKEN_FOR_PF_RELEASES}"
8+
9+
if [ -n "$1" ]; then
10+
name="\"${1}\""
11+
else
12+
echo "name not provided as first param"
13+
exit 1
14+
fi
15+
16+
if [ -n "$2" ]; then
17+
version="\"${2}\""
18+
else
19+
echo "name not provided as second param"
20+
exit 1
21+
fi
22+
23+
repository_slug=$(git remote get-url origin | cut -d':' -f2 | sed 's/\.git//')
24+
25+
output=$(curl -v https://api.github.com/repos/${repository_slug}/dispatches \
26+
-H 'Accept: application/vnd.github.everest-preview+json' \
27+
-H "Authorization: Bearer $GITHUB_ACCESS_TOKEN_FOR_PF_RELEASES" \
28+
-d "{\"event_type\": \"pact-ffi-released\", \"client_payload\": {\"name\": ${name}, \"version\" : ${version}}}" 2>&1)
29+
30+
if ! echo "${output}" | grep "HTTP\/.* 204" > /dev/null; then
31+
echo "$output" | sed "s/${GITHUB_ACCESS_TOKEN_FOR_PF_RELEASES}/********/g"
32+
echo "Failed to trigger update"
33+
exit 1
34+
else
35+
echo "Update workflow triggered"
36+
fi
37+
38+
echo "See https://github.com/${repository_slug}/actions?query=workflow%3A%22Update+Pact+FFI+Library%22"

0 commit comments

Comments
 (0)