ci: trigger snapshot rebuild even when version not bumped
MODIFY
.github/workflows/docker-test-release.yml
.github/workflows/docker-test-release.yml
@@ -9,10 +9,13 @@ on:
push-to-repos:
type: boolean
required: true
+ snapshot:
+ type: boolean
+ required: true
jobs:
build-and-push:
- name: Publish Docker images based on the latest Apiman stable release ${{ inputs.apiman-version }}
+ name: Publish Docker images based on the Apiman ${{ inputs.apiman-version }}
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/master' && github.repository_owner == 'Apiman'
# If you add a new Docker image, please add it here.
@@ -60,6 +63,7 @@ jobs:
run: |
echo "Apiman version: ${{ inputs.apiman-version }}"
echo "Push to repos: ${{ inputs.push-to-repos }}"
+ echo "Is snapshot: ${{ inputs.snapshot }}"
- name: Login to DockerHub
uses: docker/login-action@v2
@@ -74,30 +78,27 @@ jobs:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- # This step is only run if "push-to-repos" is false; i.e. workflow is build-only
- - name: Build ${{ matrix.docker-images.description }} (${{ matrix.docker-images.name }})
- if: ${{ !inputs.push-to-repos }}
- uses: docker/build-push-action@v3
- with:
- context: ${{ matrix.docker-images.path }}
- push: false
- build-args: |
- APIMAN_VERSION=${{ inputs.apiman-version }}
- ${{ matrix.docker-images.build-args }}
+ - name: Calculate Docker tags
+ env:
+ APIMAN_VERSION: ${{ inputs.apiman-version }}
+ IS_SNAPSHOT: ${{ inputs.snapshot }}
+ IMAGE_NAME: ${{ matrix.docker-images.name }}
+ # See https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#multiline-strings
+ run: |
+ DOCKER_TAGS=$(bash .github/workflows/support/calculate-docker-tags.sh)
+ echo Tags: "$DOCKER_TAGS"
+ echo 'DOCKER_TAGS<<EOF' >> $GITHUB_ENV
+ echo "$DOCKER_TAGS" >> $GITHUB_ENV
+ echo 'EOF' >> $GITHUB_ENV
- # This step is only run if "push-to-repos" is true; i.e. workflow is build-only otherwise
# You can call this reusable flow multiple times, first for build, second for build & push.
- name: Build & Push ${{ matrix.docker-images.description }} (${{ matrix.docker-images.name }})
- if: ${{ inputs.push-to-repos }}
+ if: ${{ inputs.push-to-repos }} &&
uses: docker/build-push-action@v3
with:
context: ${{ matrix.docker-images.path }}
- push: true
+ push: ${{ inputs.push-to-repos }}
build-args: |
APIMAN_VERSION=${{ inputs.apiman-version }}
${{ matrix.docker-images.build-args }}
- tags: |
- apiman/${{ matrix.docker-images.name }}:${{ inputs.apiman-version }}
- apiman/${{ matrix.docker-images.name }}:latest-release
- ghcr.io/apiman/${{ matrix.docker-images.name }}:${{ inputs.apiman-version }}
- ghcr.io/apiman/${{ matrix.docker-images.name }}:latest-release
+ tags: ${{ env.DOCKER_TAGS }}

RENAME
.github/workflows/update-release-version.yml
.github/workflows/receive-dispatch-update-release-version.yml
@@ -11,20 +11,29 @@ jobs:
- name: Checkout Apiman Docker repo
uses: actions/checkout@v3
+ - name: Default setup items
+ run: bash .git/workflows/support/setup.sh
+
- name: Update release version in docker-release flow
- run: echo ${{ github.event.client_payload.release_version }} > .github/workflows/RELEASE_VERSION
+ run: echo ${{ github.event.client_payload.release-version }} > .github/workflows/RELEASE_VERSION
+
+ - name: Tag release
+ run: git tag -a -m "Apiman Docker ${{ github.event.client_payload.release-version }}" ${{ github.event.client_payload.release-version }}
- name: Commit release version update to repository
uses: EndBug/add-and-commit@v7.2.1
with:
author_name: apiman-ci
default_author: user_info
- message: "chore(ci): update RELEASE_VERSION to ${{ github.event.client_payload.release_version }}"
- add: .workflows --force
+ message: "chore(ci): update RELEASE_VERSION to ${{ github.event.client_payload.release-version }}"
+ add: .github/workflows --force
- - name: Tag release
- run: git tag -a -m "Apiman Docker ${{ github.event.client_payload.release_version }}"
-
- - name: Create GitHub release ${{ github.event.client_payload.release_version }}
+ - name: Create GitHub release ${{ github.event.client_payload.release-version }}
uses: softprops/action-gh-release@v1
+ with:
+ tag_name: ${{ github.event.client_payload.release-version }}
+ name: ${{ github.event.client_payload.release-version }}
+ body: |
+ Apiman Docker release for Apiman version ${{ github.event.client_payload.release-version }}.
+ To access the images associated with this build, please look on Apiman's DockerHub or our GHCR registry (GitHub Packages).

ADD
.github/workflows/receive-dispatch-update-snapshot-version.yml
+name: update Apiman snapshot version
+
+on:
+ workflow_dispatch:
+ repository_dispatch:
+ types:
+ - apiman-snapshot-version
+jobs:
+ build:
+ runs-on: ubuntu-latest
+ outputs:
+ snapshot-version-changed: ${{ steps.check-version-change.outputs.snapshot-version-changed }}
+ steps:
+ - name: Checkout Apiman Docker repo
+ uses: actions/checkout@v3
+
+ - name: Default setup items
+ run: bash .github/workflows/support/setup.sh
+
+ - name: Update snapshot version in docker-release flow if changed
+ id: check-version-change
+ run: |
+ SNAPSHOT_VERSION_FILE=$(cat .github/workflows/SNAPSHOT_VERSION)
+ if [[ "$SNAPSHOT_VERSION_FILE" != "${{ github.event.client_payload.snapshot-version }}" ]]
+ then
+ echo "Old version: $SNAPSHOT_VERSION_FILE - New version: ${{ github.event.client_payload.snapshot-version }}"
+ echo ${{ github.event.client_payload.snapshot-version }} > .github/workflows/SNAPSHOT_VERSION
+ echo ::set-output name=snapshot-version-changed::true
+ else
+ echo "Snapshot version was not changed"
+ echo ::set-output name=snapshot-version-changed::false
+ fi
+
+ - name: Commit release snapshot update to repository (if version changed)
+ uses: EndBug/add-and-commit@v7.2.1
+ if: ${{ needs.read-version.outputs.snapshot-version-changed }}
+ with:
+ author_name: apiman-ci
+ default_author: user_info
+ message: "chore(ci): update SNAPSHOT_VERSION to ${{ github.event.client_payload.snapshot-version }}"
+ add: .github/workflows --force
+
+ rebuild-same-version-snapshot:
+ name: Rebuild snapshot version when code has changed, but snapshot version *not* changed
+ needs: build
+ uses: apiman/apiman-docker/.github/workflows/docker-test-release.yml@master
+ if: ${{ needs.build.outputs.snapshot-version-changed == 'false' }}
+ secrets: inherit
+ with:
+ apiman-version: ${{ github.event.client_payload.snapshot-version }}
+ push-to-repos: true
+ snapshot: true

ADD
.github/workflows/support/calculate-docker-tags.sh
+#!/bin/bash
+
+OLD_IFS=$IFS
+IFS=$'\n'
+
+export DOCKER_TAGS
+if [[ $IS_SNAPSHOT == 'true' ]]
+then
+
+read -r -d '' DOCKER_TAGS <<EOF
+apiman/$IMAGE_NAME:$APIMAN_VERSION
+apiman/$IMAGE_NAME:latest
+EOF
+
+else
+
+read -r -d '' DOCKER_TAGS <<EOF
+apiman/$IMAGE_NAME:$APIMAN_VERSION
+apiman/$IMAGE_NAME:latest
+apiman/$IMAGE_NAME:latest-release
+apiman/$IMAGE_NAME:stable
+ghcr.io/apiman/$IMAGE_NAME:$APIMAN_VERSION
+ghcr.io/apiman/$IMAGE_NAME:latest
+ghcr.io/apiman/$IMAGE_NAME:latest-release
+ghcr.io/apiman/$IMAGE_NAME:stable
+EOF
+
+fi
+
+IFS=OLD_IFS
+echo "$DOCKER_TAGS"

ADD
.github/workflows/support/setup.sh
+#!/bin/bash
+
+# Set up git user
+echo "Setting up default Git User"
+git config --global user.name "$GITHUB_ACTOR"
+git config --global user.email "${GITHUB_ACTOR}@users.noreply.github.com"

MODIFY
.github/workflows/trigger-release-from-file.yml
.github/workflows/trigger-release-from-file.yml
@@ -23,6 +23,7 @@ jobs:
with:
apiman-version: ${{ needs.read-version.outputs.version }}
push-to-repos: false
+ snapshot: false
deploy:
needs: [read-version, build]
@@ -31,3 +32,4 @@ jobs:
with:
apiman-version: ${{ needs.read-version.outputs.version }}
push-to-repos: true
+ snapshot: false

MODIFY
.github/workflows/trigger-snapshot-from-file.yml
.github/workflows/trigger-snapshot-from-file.yml
@@ -23,6 +23,7 @@ jobs:
with:
apiman-version: ${{ needs.read-version.outputs.version }}
push-to-repos: false
+ snapshot: true
deploy:
needs: [read-version, build]
@@ -31,3 +32,4 @@ jobs:
with:
apiman-version: ${{ needs.read-version.outputs.version }}
push-to-repos: true
+ snapshot: true

DELETE
.github/workflows/update-snapshot-version.yml
-name: update Apiman snapshot version
-
-on:
- workflow_dispatch:
- repository_dispatch:
- types:
- - apiman-snapshot-version
-jobs:
- build:
- runs-on: ubuntu-latest
- steps:
- - name: Checkout Apiman Docker repo
- uses: actions/checkout@v3
-
- - name: Update snapshot version in docker-release flow if changed
- id: check-version-change
- run: |
- SNAPSHOT_VERSION_FILE=$(cat .github/workflows/SNAPSHOT_VERSION)
- if [[ "$SNAPSHOT_VERSION_FILE" != "${{ github.event.client_payload.snapshot_version }}" ]]
- then
- echo "Old version: $SNAPSHOT_VERSION_FILE - New version: ${{ github.event.client_payload.snapshot_version }}"
- echo ${{ github.event.client_payload.snapshot_version }} > .github/workflows/SNAPSHOT_VERSION
- echo ::set-output name=snapshot-version-changed::true
- else
- echo "Snapshot version was not changed"
- echo ::set-output name=snapshot-version-changed::false
- fi
-
- - name: Commit release snapshot update to repository
- uses: EndBug/add-and-commit@v7.2.1
- if: ${{ steps.check-version-change.outputs.snapshot-version-changed }}
- with:
- author_name: apiman-ci
- default_author: user_info
- message: "chore(ci): update SNAPSHOT_VERSION to ${{ github.event.client_payload.snapshot_version }}"
- add: .workflows --force

ci: trigger snapshot rebuild even when version not bumped