Skip to content
This repository has been archived by the owner on Jan 5, 2023. It is now read-only.

Commit

Permalink
ci: trigger snapshot rebuild even when version not bumped
Browse files Browse the repository at this point in the history
  • Loading branch information
msavy committed Jul 18, 2022
1 parent 5ee8619 commit 969f4ed
Show file tree
Hide file tree
Showing 8 changed files with 130 additions and 63 deletions.
39 changes: 20 additions & 19 deletions .github/workflows/docker-test-release.yml
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -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 }}
Expand Up @@ -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).
52 changes: 52 additions & 0 deletions .github/workflows/receive-dispatch-update-snapshot-version.yml
@@ -0,0 +1,52 @@
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
31 changes: 31 additions & 0 deletions .github/workflows/support/calculate-docker-tags.sh
@@ -0,0 +1,31 @@
#!/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"
6 changes: 6 additions & 0 deletions .github/workflows/support/setup.sh
@@ -0,0 +1,6 @@
#!/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"
2 changes: 2 additions & 0 deletions .github/workflows/trigger-release-from-file.yml
Expand Up @@ -23,6 +23,7 @@ jobs:
with:
apiman-version: ${{ needs.read-version.outputs.version }}
push-to-repos: false
snapshot: false

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

deploy:
needs: [read-version, build]
Expand All @@ -31,3 +32,4 @@ jobs:
with:
apiman-version: ${{ needs.read-version.outputs.version }}
push-to-repos: true
snapshot: true
36 changes: 0 additions & 36 deletions .github/workflows/update-snapshot-version.yml

This file was deleted.

0 comments on commit 969f4ed

Please sign in to comment.