From 98bf124a2554f39eb7931d47eef42ca7aa738672 Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Wed, 3 Mar 2021 10:49:08 -0600 Subject: [PATCH 1/6] feat: modify action to build and consume container To speed things up further, we can build and release the actual container on release publication, and then have the action itself consume the image instead of the Dockerfile. Additionally, we can force the release process to use the latest set of changes by defining a local GHA that uses the Dockerfile instead. I've proven this works at https://github.com/weierophinney/test-local-action/, where I observed that the build happens relative to the checkout directory, and not to where the action is defined. Signed-off-by: Matthew Weier O'Phinney --- .github/actions/automatic-releases/action.yml | 20 ++++++++ .github/workflows/automatic-release.yml | 10 ++-- .../workflows/build-and-push-containers.yml | 47 +++++++++++++++++++ action.yml | 2 +- 4 files changed, 73 insertions(+), 6 deletions(-) create mode 100644 .github/actions/automatic-releases/action.yml create mode 100644 .github/workflows/build-and-push-containers.yml diff --git a/.github/actions/automatic-releases/action.yml b/.github/actions/automatic-releases/action.yml new file mode 100644 index 00000000..96c2afe8 --- /dev/null +++ b/.github/actions/automatic-releases/action.yml @@ -0,0 +1,20 @@ +# Definition of the github action +# as per https://docs.github.com/en/actions/creating-actions/creating-a-docker-container-action + +name: 'laminas/automatic-releases' +description: 'Automates automatic releases for semver-compliant repositories' + +inputs: + command-name: + description: | + Command to execute: one of + * `laminas:automatic-releases:release` + * `laminas:automatic-releases:create-merge-up-pull-request` + * `laminas:automatic-releases:switch-default-branch-to-next-minor` + required: true + +runs: + using: 'docker' + image: '../../../Dockerfile' + args: + - ${{ inputs.command-name }} diff --git a/.github/workflows/automatic-release.yml b/.github/workflows/automatic-release.yml index ad413043..6ef506cf 100644 --- a/.github/workflows/automatic-release.yml +++ b/.github/workflows/automatic-release.yml @@ -17,7 +17,7 @@ jobs: uses: "actions/checkout@v2" - name: "Release" - uses: "./" + uses: "./.github/actions/automatic-releases/" with: command-name: "laminas:automatic-releases:release" env: @@ -27,7 +27,7 @@ jobs: "GIT_AUTHOR_EMAIL": ${{ secrets.GIT_AUTHOR_EMAIL }} - name: "Create Merge-Up Pull Request" - uses: "./" + uses: "./.github/actions/automatic-releases/" with: command-name: "laminas:automatic-releases:create-merge-up-pull-request" env: @@ -37,7 +37,7 @@ jobs: "GIT_AUTHOR_EMAIL": ${{ secrets.GIT_AUTHOR_EMAIL }} - name: "Create and/or Switch to new Release Branch" - uses: "./" + uses: "./.github/actions/automatic-releases/" with: command-name: "laminas:automatic-releases:switch-default-branch-to-next-minor" env: @@ -47,7 +47,7 @@ jobs: "GIT_AUTHOR_EMAIL": ${{ secrets.GIT_AUTHOR_EMAIL }} - name: "Bump Changelog Version On Originating Release Branch" - uses: "./" + uses: "./.github/actions/automatic-releases/" with: command-name: "laminas:automatic-releases:bump-changelog" env: @@ -57,7 +57,7 @@ jobs: "GIT_AUTHOR_EMAIL": ${{ secrets.GIT_AUTHOR_EMAIL }} - name: "Create new milestones" - uses: "./" + uses: "./.github/actions/automatic-releases/" with: command-name: "laminas:automatic-releases:create-milestones" env: diff --git a/.github/workflows/build-and-push-containers.yml b/.github/workflows/build-and-push-containers.yml new file mode 100644 index 00000000..849ccb52 --- /dev/null +++ b/.github/workflows/build-and-push-containers.yml @@ -0,0 +1,47 @@ +name: Build and push containers + +on: + release: + types: [published] + +jobs: + tags: + runs-on: ubuntu-latest + outputs: + tags: ${{ steps.tags.outputs.tags }} + steps: + - name: Compile tag list + id: tags + run: | + TAG=${GITHUB_REF/refs\/tags\//} + PREFIX=ghcr.io/laminas/automatic-releases + MAJOR="${PREFIX}:$(echo ${TAG} | cut -d. -f1)" + MINOR="${MAJOR}.$(echo ${TAG} | cut -d. -f2)" + PATCH="${PREFIX}:${TAG}" + echo "::set-output name=tags::${MAJOR}%0A${MINOR}%0A${PATCH}" + + release-container: + runs-on: ubuntu-latest + needs: [tags] + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Setup QEMU + uses: docker/setup-qemu-action@v1 + - name: Setup Docker Buildx + uses: docker/setup-buildx-action@v1 + - name: Login to GitHub Container Registry + uses: docker/login-action@v1 + with: + registry: ghcr.io + username: ${{ secrets.CONTAINER_USERNAME }} + password: ${{ secrets.CONTAINER_PAT }} + - name: Build and push + uses: docker/build-push-action@v2 + with: + context: . + file: ./Dockerfile + platforms: linux/amd64 + push: true + tags: ${{ needs.tags.outputs.tags }} + diff --git a/action.yml b/action.yml index eb23a714..391291f6 100644 --- a/action.yml +++ b/action.yml @@ -15,6 +15,6 @@ inputs: runs: using: 'docker' - image: 'Dockerfile' + image: 'docker://ghcr.io/laminas/automatic-releases:1' args: - ${{ inputs.command-name }} From 8af0b901c257880dfb0e1cc57042d125f1d1750b Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Fri, 12 Mar 2021 08:58:20 -0600 Subject: [PATCH 2/6] refactor: use JSON outputs instead of multiline To address concerns with using ANSI escape sequences to create multiline outputs, this patch does the following: - Emits a JSON array instead. - Creates a single job, combining steps from each previous job; this prevents the need to use `needs`, making it possible to test the solution locally. Signed-off-by: Matthew Weier O'Phinney --- .github/workflows/build-and-push-containers.yml | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/.github/workflows/build-and-push-containers.yml b/.github/workflows/build-and-push-containers.yml index 849ccb52..c9137611 100644 --- a/.github/workflows/build-and-push-containers.yml +++ b/.github/workflows/build-and-push-containers.yml @@ -5,10 +5,8 @@ on: types: [published] jobs: - tags: + release-container: runs-on: ubuntu-latest - outputs: - tags: ${{ steps.tags.outputs.tags }} steps: - name: Compile tag list id: tags @@ -18,12 +16,7 @@ jobs: MAJOR="${PREFIX}:$(echo ${TAG} | cut -d. -f1)" MINOR="${MAJOR}.$(echo ${TAG} | cut -d. -f2)" PATCH="${PREFIX}:${TAG}" - echo "::set-output name=tags::${MAJOR}%0A${MINOR}%0A${PATCH}" - - release-container: - runs-on: ubuntu-latest - needs: [tags] - steps: + echo "::set-output name=tags::[\"${MAJOR}\",\"${MINOR}\",\"${PATCH}\"]" - name: Checkout uses: actions/checkout@v2 - name: Setup QEMU @@ -43,5 +36,4 @@ jobs: file: ./Dockerfile platforms: linux/amd64 push: true - tags: ${{ needs.tags.outputs.tags }} - + tags: ${{ join(fromJSON(steps.tags.outputs.tags), "\n") }} From 79c6f575a2a55b1a76ad4f2d2c73a2153d2065dd Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Tue, 16 Mar 2021 08:36:50 -0500 Subject: [PATCH 3/6] fix: use CSV instead of multi-line list for tags input GHA does not like newlines in strings used as part of the expression syntax. Since docker/build-push-action allows CSV, comma separated will accomplish the same goals. Signed-off-by: Matthew Weier O'Phinney --- .github/workflows/build-and-push-containers.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-and-push-containers.yml b/.github/workflows/build-and-push-containers.yml index c9137611..5585a3d9 100644 --- a/.github/workflows/build-and-push-containers.yml +++ b/.github/workflows/build-and-push-containers.yml @@ -36,4 +36,4 @@ jobs: file: ./Dockerfile platforms: linux/amd64 push: true - tags: ${{ join(fromJSON(steps.tags.outputs.tags), "\n") }} + tags: ${{ join(fromJSON(steps.tags.outputs.tags), ",") }} From 9c347624bae96b12ab0993f1bc65f356c1f916ae Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Mon, 29 Mar 2021 10:33:27 -0500 Subject: [PATCH 4/6] qa: prefix secrets to make clear they are specific to this repo Prefixed with `AUTOMATIC_RELEASES_` Signed-off-by: Matthew Weier O'Phinney --- .github/workflows/build-and-push-containers.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build-and-push-containers.yml b/.github/workflows/build-and-push-containers.yml index 5585a3d9..ac44c662 100644 --- a/.github/workflows/build-and-push-containers.yml +++ b/.github/workflows/build-and-push-containers.yml @@ -27,8 +27,8 @@ jobs: uses: docker/login-action@v1 with: registry: ghcr.io - username: ${{ secrets.CONTAINER_USERNAME }} - password: ${{ secrets.CONTAINER_PAT }} + username: ${{ secrets.AUTOMATIC_RELEASES_CONTAINER_USERNAME }} + password: ${{ secrets.AUTOMATIC_RELEASES_CONTAINER_PAT }} - name: Build and push uses: docker/build-push-action@v2 with: From dc9d0b046d9a107dfe2e9109f5f0be26bffb5d33 Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Mon, 29 Mar 2021 10:34:31 -0500 Subject: [PATCH 5/6] qa: whitespace between job steps in container build workflow Signed-off-by: Matthew Weier O'Phinney --- .github/workflows/build-and-push-containers.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/build-and-push-containers.yml b/.github/workflows/build-and-push-containers.yml index ac44c662..972a00f9 100644 --- a/.github/workflows/build-and-push-containers.yml +++ b/.github/workflows/build-and-push-containers.yml @@ -17,18 +17,23 @@ jobs: MINOR="${MAJOR}.$(echo ${TAG} | cut -d. -f2)" PATCH="${PREFIX}:${TAG}" echo "::set-output name=tags::[\"${MAJOR}\",\"${MINOR}\",\"${PATCH}\"]" + - name: Checkout uses: actions/checkout@v2 + - name: Setup QEMU uses: docker/setup-qemu-action@v1 + - name: Setup Docker Buildx uses: docker/setup-buildx-action@v1 + - name: Login to GitHub Container Registry uses: docker/login-action@v1 with: registry: ghcr.io username: ${{ secrets.AUTOMATIC_RELEASES_CONTAINER_USERNAME }} password: ${{ secrets.AUTOMATIC_RELEASES_CONTAINER_PAT }} + - name: Build and push uses: docker/build-push-action@v2 with: From efeff72bb15b12e48dc100780ae15223fd65d6af Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Mon, 29 Mar 2021 10:38:02 -0500 Subject: [PATCH 6/6] qa: simplify bash pattern matching when matching tag name Signed-off-by: Matthew Weier O'Phinney --- .github/workflows/build-and-push-containers.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-and-push-containers.yml b/.github/workflows/build-and-push-containers.yml index 972a00f9..60561d0e 100644 --- a/.github/workflows/build-and-push-containers.yml +++ b/.github/workflows/build-and-push-containers.yml @@ -11,7 +11,7 @@ jobs: - name: Compile tag list id: tags run: | - TAG=${GITHUB_REF/refs\/tags\//} + TAG=${GITHUB_REF#refs/tags/} PREFIX=ghcr.io/laminas/automatic-releases MAJOR="${PREFIX}:$(echo ${TAG} | cut -d. -f1)" MINOR="${MAJOR}.$(echo ${TAG} | cut -d. -f2)"