diff --git a/.github/workflows/audit.yml b/.github/workflows/audit.yml index f4fd86a..6aaa5e9 100644 --- a/.github/workflows/audit.yml +++ b/.github/workflows/audit.yml @@ -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 }} diff --git a/.github/workflows/manual_release_package.yml b/.github/workflows/manual_release_package.yml deleted file mode 100644 index 9fa0f92..0000000 --- a/.github/workflows/manual_release_package.yml +++ /dev/null @@ -1,38 +0,0 @@ -name: Release Docker image with updated packaging - -on: - workflow_dispatch: - inputs: - release: - description: Release number - required: true - type: number - -jobs: - release: - runs-on: ubuntu-latest - - steps: - - - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - - uses: ruby/setup-ruby@v1 - - - name: Prepare release - id: prepare-release - run: script/workflows/prepare-release.sh - env: - RELEASE: ${{ inputs.release }} - - - name: Commit and push version and changelog - uses: EndBug/add-and-commit@v4 - with: - add: CHANGELOG.md - author_name: Beth Skurrie via Github Action - author_email: beth@bethesque.com - message: 'chore(release): version ${{ steps.prepare-release.outputs.tag }}' - tag: '${{ steps.prepare-release.outputs.tag }}' - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/release_image.yml b/.github/workflows/release_image.yml index 155b2a5..9bcaa42 100644 --- a/.github/workflows/release_image.yml +++ b/.github/workflows/release_image.yml @@ -15,7 +15,20 @@ on: - major - minor - patch - + # Sets the first part of the Docker tag - this will update the VERSION file + version: + description: "Custom version, requires increment to be set" + required: false + tag: + description: "Custom Docker image tag (note - this won't update the VERSION file and is for non-prod releases only)" + required: false + push_to_latest: + description: 'Should push to latest' + type: boolean + default: true + docker_repository: + description: The Docker repository to which the image should be published + default: pactfoundation jobs: release: runs-on: ubuntu-latest @@ -35,5 +48,9 @@ jobs: env: DOCKER_HUB_USERNAME: ${{ secrets.DOCKER_HUB_USERNAME }} DOCKER_HUB_TOKEN: ${{ secrets.DOCKER_HUB_TOKEN }} - CUSTOM_TAG: ${{ github.event.client_payload.tag }} - INCREMENT: ${{ github.event.inputs.increment }} + DOCKER_IMAGE_ORG_AND_NAME: ${{ github.event.inputs.docker_repository }}/pact-cli + VERSION: ${{ github.event.inputs.version }} + INCREMENT: ${{ github.event.client_payload.increment }}${{ github.event.inputs.increment }} + 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 }} \ No newline at end of file diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 0676ad3..ca88836 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,6 +1,6 @@ name: Test -on: [push, pull_request] +on: [push, pull_request, workflow_dispatch] jobs: test: diff --git a/.github/workflows/update_gems.yml b/.github/workflows/update_gems.yml deleted file mode 100644 index a5d7b65..0000000 --- a/.github/workflows/update_gems.yml +++ /dev/null @@ -1,66 +0,0 @@ -# TODO abort if there are no changes to the Gemfile. - -name: Update gems - -on: - repository_dispatch: - types: - - gem-released - workflow_dispatch: - inputs: - released_gem_name: - description: The name of the gem that was released - default: pact - required: false - released_gem_version: - description: The version of the game that was released - required: false - released_gem_version_increment: - description: "The version increment" - required: false - default: "" - type: choice - options: - - "" - - patch - - minor - - major - - pre - -env: - RELEASED_GEM_NAME: '${{ github.event.client_payload.name }}${{ github.event.inputs.released_gem_name }}' - RELEASED_GEM_VERSION: '${{ github.event.client_payload.version }}${{ github.event.inputs.released_gem_version }}' - RELEASED_GEM_INCREMENT: '${{ github.event.client_payload.increment }}${{ github.event.inputs.released_gem_version_increment }}' - -jobs: - release: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - uses: ruby/setup-ruby@v1 - - - name: Configure git - run: | - git config --global user.email "${GITHUB_ACTOR}@users.noreply.github.com" - git config --global user.name "${GITHUB_ACTOR}" - git config --global push.default current - - - name: Update gems - run: script/update-gems-workflow/update-gems.sh - - - name: Detect changes - run: script/update-gems-workflow/detect-changes.sh - - - name: Git commit and push - run: script/update-gems-workflow/git-commit-and-push-gemfile.sh - - - name: Trigger release - uses: peter-evans/repository-dispatch@v1 - if: ${{ github.repository_owner == 'pact-foundation' }} - with: - token: ${{ secrets.GHTOKENFORPACTCLIRELEASE }} - event-type: release-triggered - client-payload: '{"increment": "${{ github.event.client_payload.increment }}${{ github.event.inputs.released_gem_version_increment }}"}' diff --git a/RELEASING.md b/RELEASING.md index c726297..7eacb8b 100644 --- a/RELEASING.md +++ b/RELEASING.md @@ -1,5 +1,34 @@ # 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. +> 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. + +## 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). + +This causes the `update_gems.yml` workflow to be run. At the end of the workflow, it will trigger a release by invoking the `repository_dispatch` action with type `release-triggered`, passing in the increment. + +Note: sometimes bundler cannot find the newly released gem straight away, and the job needs to be re-run via the UI. + +### Manual releases of the Docker image triggered by the release of one of the Pact gem + +* On the Github Actions page, select `Update gems` +* Select `Run workflow` +* To attempt to update a particular gem - update the default `released_gem_name` & set the required `released_gem_version` and then click `Run workflow`. This should be the normal process if a Pact gem has been updated. +* To release a non-minor version change, select the `released_gem_version_increment` you want along with the above values, and click `Run workflow`. +* If the `Gemfile.lock` is updated, the results will be committed back to the repository, along with an updated `lib/pact/cli/version.rb` set to the `released_gem_version_increment` (which defaults to minor) +* This will trigger an automated release of the Docker image, where the Docker semver tag will be updated by a the same `released_gem_version_increment` + + +## Manually releasing the Docker image + +* On the Github Actions page, select `Release Docker image` +* Select `Run workflow` +* 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. \ No newline at end of file diff --git a/script/release-workflow/docker-push.sh b/script/release-workflow/docker-push.sh index a1bd2dd..adbc365 100755 --- a/script/release-workflow/docker-push.sh +++ b/script/release-workflow/docker-push.sh @@ -2,22 +2,18 @@ set -euo >/dev/null -# Enable when we bump the major version to 1 (which we should) -# if [ -n "${MAJOR_TAG}" ]; then -# docker tag ${DOCKER_IMAGE_ORG_AND_NAME}:latest ${DOCKER_IMAGE_ORG_AND_NAME}:${MAJOR_TAG} -# docker push ${DOCKER_IMAGE_ORG_AND_NAME}:${MAJOR_TAG} -# docker push ${DOCKER_IMAGE_ORG_AND_NAME}:latest -# fi +push() { + 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} +fi -docker buildx build --platform=linux/amd64 \ - --output=type=image,push=true \ - -t ${DOCKER_IMAGE_ORG_AND_NAME}:latest \ - -t ${DOCKER_IMAGE_ORG_AND_NAME}:${TAG} . - ## We will temporarily publish a multi manifest built as $TAG-multi - ## To avoid any issues with existing users. We can ask users for - ## Feedback and then promote to a multi-manifest build -docker buildx build --platform=linux/amd64,linux/arm64,linux/arm \ - --output=type=image,push=true \ - -t ${DOCKER_IMAGE_ORG_AND_NAME}:latest-multi \ - -t ${DOCKER_IMAGE_ORG_AND_NAME}:${TAG}-multi . \ No newline at end of file +push ${TAG} + +if [ "${PUSH_TO_LATEST}" != "false" ]; then + push latest +fi \ No newline at end of file