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

Chore/rel 1.x prep #118

Merged
merged 4 commits into from
Sep 8, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
6 changes: 5 additions & 1 deletion .github/workflows/audit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ jobs:
strategy:
fail-fast: false
matrix:
DOCKER_TARGET_PLATFORM: [linux/arm, linux/arm64, linux/amd64]
DOCKER_TARGET_PLATFORM: [
# linux/arm, # Disabled whilst waiting for next release of trivy with published arm artefacts
linux/arm64,
linux/amd64
]
runs-on: ubuntu-latest
env:
DOCKER_TARGET_PLATFORM: ${{ matrix.DOCKER_TARGET_PLATFORM }}
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/release_image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ jobs:
env:
DOCKER_HUB_USERNAME: ${{ secrets.DOCKER_HUB_USERNAME }}
DOCKER_HUB_TOKEN: ${{ secrets.DOCKER_HUB_TOKEN }}
DOCKER_REPOSITORY: ${{ github.event.inputs.docker_repository }}
TAG: ${{ github.event.inputs.tag }}
DOCKER_IMAGE_ORG_AND_NAME: ${{ github.event.inputs.docker_repository }}/pact-cli
VERSION: ${{ github.event.inputs.version }}
# populate INCREMENT from workflow_dispatch or repository_dispatch
INCREMENT: ${{ github.event.client_payload.increment }}${{ github.event.inputs.increment }}
PUSH_TO_LATEST: ${{ github.event.inputs.push_to_latest }}
CUSTOM_TAG: ${{ github.event.client_payload.tag }}${{ github.event.inputs.tag }}
# populate INCREMENT from workflow_dispatch or repository_dispatch
PUSH_TO_LATEST: ${{ github.event.inputs.push_to_latest }}
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Test

on: [push, pull_request]
on: [push, pull_request, workflow_dispatch]

jobs:
test:
Expand Down
52 changes: 52 additions & 0 deletions .github/workflows/update-and-prepare-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# TODO abort if there are no changes to the Gemfile.
YOU54F marked this conversation as resolved.
Show resolved Hide resolved

name: Update gems and prepare to release Docker image

on:
repository_dispatch:
types:
- gem-released-disabled
workflow_dispatch:

jobs:
release:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: ruby/setup-ruby@v1

- id: update
run: script/workflows/update.sh
env:
RELEASED_GEM_NAME: ${{ github.event.client_payload.name }}
RELEASED_GEM_VERSION: ${{ github.event.client_payload.version }}

- name: Commit and push gem file changes
uses: EndBug/add-and-commit@v4
with:
add: Gemfile.lock
author_name: Beth Skurrie via Github Action
YOU54F marked this conversation as resolved.
Show resolved Hide resolved
author_email: [email protected]
message: 'feat(gems): ${{ steps.update.outputs.commit_message }}'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- id: prepare-release
name: Update version and generate changelog
run: script/workflows/prepare-release.sh
env:
INCREMENT: ${{ github.event.client_payload.increment }}

- name: Commit and push version and changelog
uses: EndBug/add-and-commit@v4
with:
add: lib/pact/cli/version.rb Gemfile.lock CHANGELOG.md
author_name: Beth Skurrie via Github Action
author_email: [email protected]
message: 'chore(release): version ${{ steps.prepare-release.outputs.tag }}'
tag: '${{ steps.prepare-release.outputs.tag }}'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
41 changes: 41 additions & 0 deletions .github/workflows/update-gems.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# TODO abort if there are no changes to the Gemfile.
YOU54F marked this conversation as resolved.
Show resolved Hide resolved

name: Update gems

on:
repository_dispatch:
types:
- gem-released
workflow_dispatch:

jobs:
release:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: ruby/setup-ruby@v1

- id: update
run: script/workflows/update.sh
env:
RELEASED_GEM_NAME: ${{ github.event.client_payload.name }}
RELEASED_GEM_VERSION: ${{ github.event.client_payload.version }}

- name: Commit and push gem file changes
uses: EndBug/add-and-commit@v4
with:
add: Gemfile.lock
author_name: Beth Skurrie via Github Action
author_email: [email protected]
message: 'feat(gems): ${{ steps.update.outputs.commit_message }}'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Trigger release
uses: peter-evans/repository-dispatch@v1
with:
token: ${{ secrets.GHTOKENFORPACTCLIRELEASE }}
event-type: release-triggered
66 changes: 0 additions & 66 deletions .github/workflows/update_gems.yml

This file was deleted.

26 changes: 1 addition & 25 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# Pact CLI

This tool provides an amalgamated CLI of all the Pact CLI tools available in the Pact Ruby implementation (publish and verify pacts, and interact with the Pact Broker). While it is functionally the same as the [pact-ruby-standalone](https://github.com/pact-foundation/pact-ruby-standalone) it is packaged as a Docker container and a single top level entrypoint (`pact`). You can pull the `pactfoundation/pact-cli` image from [Dockerhub](https://hub.docker.com/r/pactfoundation/pact-cli)

> Note: On 23rd May 2023, the format of the docker tag changed from ending with the Pact Cli Gem version (`0.51.0.4`), where `.4` noted a change to the one of the packaged gems, to ending with the Pact Cli gem version (`0.52.0-pactcli0.52.0`). Read about the new versioning scheme [here](#versioning).
This tool provides an amalgamated CLI of all the Pact CLI tools available in the Pact Ruby implementation (publish and verify pacts, and interact with the Pact Broker). While it is functionally the same as the [pact-ruby-standalone](https://github.com/pact-foundation/pact-ruby-standalone) it is packaged as a Docker container and a single top level entrypoint (`pact`).

[![Maintenance](https://img.shields.io/badge/Maintained%3F-yes-green.svg)](https://GitHub.com/pact-foundation/pact-msw-adapter/graphs/commit-activity)

Expand Down Expand Up @@ -218,28 +216,6 @@ lib
pact-cli.gemspec
```

## Versioning

The Docker image tag uses a semantic-like versioning scheme (Docker tags don't support the `+` symbol, so we cannot implement a strict semantic version). The format of the tag is `M.m.p-pactcli<pact_cli_version>` eg. `0.52.0-pactcli0.52.0`. The `M.m.p` (eg. `0.52.0`) is the semantic part of the tag number, while the `-pactcli<pact_cli_version>` suffix is purely informational.

The major version will be bumped for:

* Major increments of the Pact Cli gem
* Major increments of the base image that contain backwards incompatible changes (eg. dropping support for Docker 19)
* Any other backwards incompatible changes made for any reason (eg. environment variable mappings, entrypoints, tasks, supported auth)

The minor version will be bumped for:

* Minor increments of the Pact Cli gem
* Additional non-breaking functionality added to the Docker image

The patch version will be bumped for:

* Patch increments of the Pact Cli gem
* Other fixes to the Docker image

Until May 2023, the versioning scheme used the `M.m.p` from the Pact Cli gem, with an additional `RELEASE` number at the end (eg. `0.51.0.4`). This scheme was replace by the current scheme because it was unable to semantically convey changes made to the Docker image that were unrelated to a Pact Cli gem version change (eg. alpine upgrades).

## Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/pact-foundation/pact-ruby-cli.
Expand Down
12 changes: 3 additions & 9 deletions RELEASING.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
# Releasing

> Manual releases are not generally necessary.

When one of the Pact gems is released, it sends a repository dispatch notification with event type `gem-released`, which triggers the `Update gems` Github Action that updates the gems and commits the changes. The `Release` workflow is then triggered by another repository dispatch action of type `release-triggered` which generates the release notes, builds and publishes the Docker image, and creates the git commits and tags.

If the packaging code needs to be updated, a manual release can be performed by running the `Release Docker image with updated packaging` workflow from the UI.

# Releasing

Please read the [versioning](/#versioning) section of the README file before continuing.

The semantic version part of the tag is stored in the `VERSION` file at the root of the repository.

> Manual releases are not generally necessary.

## Automatic releases of the Docker image triggered by the release of one of the Pact gem

When one of the Pact gems is released by the Github Action in its repository, the `repository_dispatch` action of the `pact-ruby-cli` repository will be invoked with the type `gem-released`, and the release details (name, version, increment).
Expand All @@ -37,4 +31,4 @@ Note: sometimes bundler cannot find the newly released gem straight away, and th
* To release a minor version change, do not set any inputs - just click `Run workflow`. This should be the normal process if you've done some changes to the Docker image.
* To release a non-minor version change, select the increment you want, and click `Run workflow`.
* To set a custom version number (not sure of the usecase for this, but just in case...), set both the version AND the increment and click `Run workflow`.
* To do a completely custom tag, just set the "Custom Docker image tag" and click `Run workflow`. If you do this, the VERSION file will NOT be updated. It is for testing purposes only.
* To do a completely custom tag, just set the "Custom Docker image tag" and click `Run workflow`. If you do this, the VERSION file will NOT be updated. It is for testing purposes only.
13 changes: 1 addition & 12 deletions script/release-workflow/docker-push.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,18 @@

set -euo >/dev/null

## Publish a multi arch build with -multi added to the tag
## ($TAG||$MAJOR_TAG||$LATEST)-multi
push_multi() {
## These will use cached builds, so wont build every time.
docker buildx build --platform=linux/amd64,linux/arm64,linux/arm \
--output=type=image,push=true \
-t ${DOCKER_IMAGE_ORG_AND_NAME}:$1-multi .
}
push() {
docker buildx build --platform=linux/amd64 \
docker buildx build --platform=linux/amd64,linux/arm64,linux/arm \
--output=type=image,push=true \
-t ${DOCKER_IMAGE_ORG_AND_NAME}:$1 .
}

if [ -n "${MAJOR_TAG:-}" ]; then
push ${MAJOR_TAG}
push_multi ${MAJOR_TAG}
fi

push ${TAG}
push_multi ${TAG}

if [ "${PUSH_TO_LATEST}" != "false" ]; then
push latest
push_multi latest
fi
21 changes: 21 additions & 0 deletions script/release-workflow/next-docker-tag.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/sh

set -eu

gem_version_from_gemfile_lock() {
grep "pact_broker (" pact_broker/Gemfile.lock | awk -F '[()]' '{print $2}'
}

gem_version=$(ruby -I lib -e "require 'pact/cli/version.rb'; puts Pact::Cli::VERSION")
existing_tags=$(git tag)
existing_release_numbers_for_current_gem_version=$(echo "$existing_tags" | grep "${gem_version}\." | sed 's/'${gem_version}'\.//g' | grep -E "^[0-9]+$" | cat)

if [ -n "${existing_release_numbers_for_current_gem_version}" ]; then
last_release_number=$(printf "0\n${existing_release_numbers_for_current_gem_version}" | sort -g | tail -1)
next_release_number=$(( $last_release_number + 1 ))
else
next_release_number=0
fi

tag="${gem_version}.${next_release_number}"
echo $tag
15 changes: 0 additions & 15 deletions script/release-workflow/prepare-release.sh
Original file line number Diff line number Diff line change
@@ -1,22 +1,7 @@
#!/bin/sh

set -euo >/dev/null
docker_compose_files=$(find . -name "docker-compose*.yml" -not -name "*test*")

for file in $docker_compose_files; do
cat $file | sed -e "s~image: pactfoundation/pact-cli:.*~image: pactfoundation/pact-cli:${TAG}~g" > dc-tmp
mv dc-tmp $file
done

bundle exec conventional-changelog version=${TAG} force=true

if [ -n "$VERSION" ]; then
bundle exec bump set $VERSION --no-commit
git add VERSION
else
echo "Cannot update VERSION file as no VERSION has been specified"
fi

git add CHANGELOG.md
git add docker-compose*
git commit -m "chore(release): version ${TAG}"
32 changes: 9 additions & 23 deletions script/release-workflow/set-env-vars.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,13 @@ else
export ARCH=amd64
fi

if [ -z "$TAG" ]; then
if [ -n "$VERSION" ] && [ -z "$INCREMENT" ]; then
echo "If VERSION is specified, then INCREMENT must also be specified"
exit 1
fi

export INCREMENT=${INCREMENT:-minor}

if [ -z "$VERSION" ]; then
export VERSION=$(bundle exec bump show-next $INCREMENT)
fi

export PACT_CLI_VERSION=$(ruby -I lib -e "require 'pact/cli/version.rb'; puts Pact::Cli::VERSION")
export TAG="$VERSION-pactcli${PACT_CLI_VERSION}"
export MAJOR_TAG="$(echo $VERSION | cut -d'.' -f1)"

echo "INCREMENT=$INCREMENT"
echo "VERSION=$VERSION"
echo "PACT_CLI_VERSION=$PACT_CLI_VERSION"
echo "TAG=$TAG"
echo "MAJOR_TAG=$MAJOR_TAG"
if [ -n "${CUSTOM_TAG:-}" ]; then
export TAG=$CUSTOM_TAG
export MAJOR_TAG=""
else
echo "TAG=$TAG"
fi
export TAG=$(script/release-workflow/next-docker-tag.sh)
export MAJOR_TAG=$(echo $TAG | cut -d'.' -f1)
fi

echo "Set TAG=${TAG}"
echo "Set MAJOR_TAG=${MAJOR_TAG}"
1 change: 1 addition & 0 deletions script/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

docker build . -t pactfoundation/pact-cli
docker run --rm pactfoundation/pact-cli:latest
docker run --rm pactfoundation/pact-cli:latest --help
docker run --rm pactfoundation/pact-cli:latest mock-service --help
docker run --rm pactfoundation/pact-cli:latest pact-broker --help
docker run --rm pactfoundation/pact-cli:latest pactflow --help
Expand Down
8 changes: 0 additions & 8 deletions script/update-gems-workflow/detect-changes.sh

This file was deleted.

Loading