diff --git a/.github/workflows/docker-test-release.yml b/.github/workflows/docker-test-release.yml index 1985c6c..0669660 100644 --- a/.github/workflows/docker-test-release.yml +++ b/.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,24 @@ 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 }} + run: | + DOCKER_TAGS=$(bash .github/workflows/support/calculate-docker-tags.sh) + echo Tags: "$DOCKER_TAGS" + echo DOCKER_TAGS="$DOCKER_TAGS" >> $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 }} diff --git a/.github/workflows/update-release-version.yml b/.github/workflows/receive-dispatch-update-release-version.yml similarity index 51% rename from .github/workflows/update-release-version.yml rename to .github/workflows/receive-dispatch-update-release-version.yml index 5a26a16..79199c4 100644 --- a/.github/workflows/update-release-version.yml +++ b/.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). diff --git a/.github/workflows/receive-dispatch-update-snapshot-version.yml b/.github/workflows/receive-dispatch-update-snapshot-version.yml new file mode 100644 index 0000000..267a646 --- /dev/null +++ b/.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 diff --git a/.github/workflows/support/calculate-docker-tags.sh b/.github/workflows/support/calculate-docker-tags.sh new file mode 100644 index 0000000..db0b39b --- /dev/null +++ b/.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 < .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