From 84f1404c67b33f1b5b860339e7b14c807b1ae5f0 Mon Sep 17 00:00:00 2001 From: Adam Chalkley Date: Fri, 12 Jan 2024 17:20:54 -0600 Subject: [PATCH] Replace choffmeister/git-describe-semver GH action Replace the (currently) problematic GitHub Action with a custom job (`git_describe_semver`) that explicitly uses the v0.3.11 version of the Docker container to generate the release asset release version. That version is captured as the job's `version` output which is referenced by other jobs in the build-images and release-build workflows. Those jobs are set as dependent on the `git_describe_semver` job so that they only run after the asset release version is computed. Since the value is computed once at the start of the workflow, I've updated the `actions/checkout` step for each job to use the default checkout option(s) instead of pulling the full repo history each time. This should (somewhat) optimize that step in the build process. refs GH-1276 --- .github/workflows/build-images.yml | 263 ++++++++++------------------ .github/workflows/release-build.yml | 85 +++++++-- 2 files changed, 162 insertions(+), 186 deletions(-) diff --git a/.github/workflows/build-images.yml b/.github/workflows/build-images.yml index d68dde66..10db5d6e 100644 --- a/.github/workflows/build-images.yml +++ b/.github/workflows/build-images.yml @@ -20,17 +20,20 @@ on: workflow_dispatch: jobs: - build_stable_image_using_makefile: - name: Build stable image using Makefile + git_describe_semver: + name: Generate semantic release version using git-describe-semver runs-on: ubuntu-latest # Default: 360 minutes - timeout-minutes: 10 + timeout-minutes: 5 + # https://docs.github.com/en/actions/using-jobs/defining-outputs-for-jobs + outputs: + version: ${{ steps.git-describe-semver.outputs.version }} steps: - name: Print Docker version run: docker --version - - name: Clone full repo history + - name: Clone repo with full history uses: actions/checkout@v4 with: # Needed in order to retrieve tags for use with semver calculations @@ -47,32 +50,72 @@ jobs: # run: git config --global --add safe.directory "$GITHUB_WORKSPACE" run: git config --global --add safe.directory "${PWD}" - # bsdmainutils provides "column" which is used by the Makefile - - name: Install Ubuntu packages - run: sudo apt-get update && sudo apt-get install -y --no-install-recommends make gcc bsdmainutils - - - name: Generate semantic version for project - id: use-git-describe-semver - uses: choffmeister/git-describe-semver@v0.3.11 - with: - fallback: v0.0.0 - drop-prefix: false - prerelease-prefix: dev - prerelease-suffix: "" - prerelease-timestamped: false + # - name: Generate semantic version for project + # id: use-git-describe-semver + # uses: choffmeister/git-describe-semver@v0.3.11 + # with: + # fallback: v0.0.0 + # drop-prefix: false + # prerelease-prefix: dev + # prerelease-suffix: "" + # prerelease-timestamped: false # - name: Install git-describe-semver # id: install-git-describe-semver # run: go install github.com/choffmeister/git-describe-semver@latest # https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#example-of-setting-an-output-parameter - # - name: Record semantic version using git-describe-semver - # id: use-git-describe-semver - # run: echo "version=$($HOME/go/bin/git-describe-semver)" >> "$GITHUB_OUTPUT" + # https://stackoverflow.com/questions/59954185/github-action-split-long-command-into-multiple-lines + - name: Record semantic version using git-describe-semver + id: git-describe-semver + run: > + echo "version=$( + docker container run + --platform linux/amd64 + --rm + -it + -v $PWD:/code + -w /code + ghcr.io/choffmeister/git-describe-semver:0.3.11 + --fallback 'v0.0.0' + --drop-prefix=false + --prerelease-prefix 'dev' + --prerelease-suffix "" + --prerelease-timestamped=false + )" >> "$GITHUB_OUTPUT" + + build_stable_image_using_makefile: + name: Build stable image using Makefile + needs: git_describe_semver + runs-on: ubuntu-latest + # Default: 360 minutes + timeout-minutes: 10 + + steps: + - name: Print Docker version + run: docker --version + + - name: Clone repo with default settings + uses: actions/checkout@v4 + + # Mark the current working directory as a safe directory in git to + # resolve "dubious ownership" complaints. + # + # https://docs.github.com/en/actions/learn-github-actions/variables#default-environment-variables + # https://confluence.atlassian.com/bbkb/git-command-returns-fatal-error-about-the-repository-being-owned-by-someone-else-1167744132.html + # https://github.com/actions/runner-images/issues/6775 + # https://github.com/actions/checkout/issues/766 + - name: Mark the current working directory as a safe directory in git + # run: git config --global --add safe.directory "$GITHUB_WORKSPACE" + run: git config --global --add safe.directory "${PWD}" + + # bsdmainutils provides "column" which is used by the Makefile + - name: Install Ubuntu packages + run: sudo apt-get update && sudo apt-get install -y --no-install-recommends make gcc bsdmainutils - name: Build stable image run: | - export REPO_VERSION=${{ steps.use-git-describe-semver.outputs.version }} + export REPO_VERSION=${{ needs.git_describe_semver.outputs.version }} make build-stable - name: List generated Docker images @@ -80,6 +123,7 @@ jobs: build_oldstable_alpine_x64_image_using_makefile: name: Build oldstable Alpine x64 image using Makefile + needs: git_describe_semver runs-on: ubuntu-latest # Default: 360 minutes timeout-minutes: 10 @@ -88,11 +132,8 @@ jobs: - name: Print Docker version run: docker --version - - name: Clone full repo history + - name: Clone repo with default settings uses: actions/checkout@v4 - with: - # Needed in order to retrieve tags - fetch-depth: 0 # Mark the current working directory as a safe directory in git to # resolve "dubious ownership" complaints. @@ -109,19 +150,9 @@ jobs: - name: Install Ubuntu packages run: sudo apt-get update && sudo apt-get install -y --no-install-recommends make gcc bsdmainutils - - name: Generate semantic version for project - id: use-git-describe-semver - uses: choffmeister/git-describe-semver@v0.3.11 - with: - fallback: v0.0.0 - drop-prefix: false - prerelease-prefix: dev - prerelease-suffix: "" - prerelease-timestamped: false - - name: Build oldstable Alpine x64 image run: | - export REPO_VERSION=${{ steps.use-git-describe-semver.outputs.version }} + export REPO_VERSION=${{ needs.git_describe_semver.outputs.version }} make build-oldstable-alpine-buildx64 - name: List generated Docker images @@ -129,6 +160,7 @@ jobs: build_oldstable_alpine_x86_image_using_makefile: name: Build oldstable Alpine x86 image using Makefile + needs: git_describe_semver runs-on: ubuntu-latest # Default: 360 minutes timeout-minutes: 10 @@ -137,7 +169,7 @@ jobs: - name: Print Docker version run: docker --version - - name: Clone full repo history + - name: Clone repo with default settings uses: actions/checkout@v4 with: # Needed in order to retrieve tags for use with semver calculations @@ -158,19 +190,9 @@ jobs: - name: Install Ubuntu packages run: sudo apt-get update && sudo apt-get install -y --no-install-recommends make gcc bsdmainutils - - name: Generate semantic version for project - id: use-git-describe-semver - uses: choffmeister/git-describe-semver@v0.3.11 - with: - fallback: v0.0.0 - drop-prefix: false - prerelease-prefix: dev - prerelease-suffix: "" - prerelease-timestamped: false - - name: Build oldstable Alpine x86 image run: | - export REPO_VERSION=${{ steps.use-git-describe-semver.outputs.version }} + export REPO_VERSION=${{ needs.git_describe_semver.outputs.version }} make build-oldstable-alpine-buildx86 - name: List generated Docker images @@ -178,6 +200,7 @@ jobs: build_stable_alpine_x64_image_using_makefile: name: Build stable Alpine x64 image using Makefile + needs: git_describe_semver runs-on: ubuntu-latest # Default: 360 minutes timeout-minutes: 10 @@ -186,11 +209,8 @@ jobs: - name: Print Docker version run: docker --version - - name: Clone full repo history + - name: Clone repo with default settings uses: actions/checkout@v4 - with: - # Needed in order to retrieve tags - fetch-depth: 0 # Mark the current working directory as a safe directory in git to # resolve "dubious ownership" complaints. @@ -207,19 +227,9 @@ jobs: - name: Install Ubuntu packages run: sudo apt-get update && sudo apt-get install -y --no-install-recommends make gcc bsdmainutils - - name: Generate semantic version for project - id: use-git-describe-semver - uses: choffmeister/git-describe-semver@v0.3.11 - with: - fallback: v0.0.0 - drop-prefix: false - prerelease-prefix: dev - prerelease-suffix: "" - prerelease-timestamped: false - - name: Build stable Alpine x64 image run: | - export REPO_VERSION=${{ steps.use-git-describe-semver.outputs.version }} + export REPO_VERSION=${{ needs.git_describe_semver.outputs.version }} make build-stable-alpine-buildx64 - name: List generated Docker images @@ -227,6 +237,7 @@ jobs: build_stable_alpine_x86_image_using_makefile: name: Build stable Alpine x86 image using Makefile + needs: git_describe_semver runs-on: ubuntu-latest # Default: 360 minutes timeout-minutes: 10 @@ -235,11 +246,8 @@ jobs: - name: Print Docker version run: docker --version - - name: Clone full repo history + - name: Clone repo with default settings uses: actions/checkout@v4 - with: - # Needed in order to retrieve tags for use with semver calculations - fetch-depth: 0 # Mark the current working directory as a safe directory in git to # resolve "dubious ownership" complaints. @@ -256,19 +264,9 @@ jobs: - name: Install Ubuntu packages run: sudo apt-get update && sudo apt-get install -y --no-install-recommends make gcc bsdmainutils - - name: Generate semantic version for project - id: use-git-describe-semver - uses: choffmeister/git-describe-semver@v0.3.11 - with: - fallback: v0.0.0 - drop-prefix: false - prerelease-prefix: dev - prerelease-suffix: "" - prerelease-timestamped: false - - name: Build stable Alpine x86 image run: | - export REPO_VERSION=${{ steps.use-git-describe-semver.outputs.version }} + export REPO_VERSION=${{ needs.git_describe_semver.outputs.version }} make build-stable-alpine-buildx86 - name: List generated Docker images @@ -276,6 +274,7 @@ jobs: build_unstable_alpine_x64_image_using_makefile: name: Build unstable Alpine x64 image using Makefile + needs: git_describe_semver runs-on: ubuntu-latest # Default: 360 minutes timeout-minutes: 10 @@ -284,11 +283,8 @@ jobs: - name: Print Docker version run: docker --version - - name: Clone full repo history + - name: Clone repo with default settings uses: actions/checkout@v4 - with: - # Needed in order to retrieve tags - fetch-depth: 0 # Mark the current working directory as a safe directory in git to # resolve "dubious ownership" complaints. @@ -305,19 +301,9 @@ jobs: - name: Install Ubuntu packages run: sudo apt-get update && sudo apt-get install -y --no-install-recommends make gcc bsdmainutils - - name: Generate semantic version for project - id: use-git-describe-semver - uses: choffmeister/git-describe-semver@v0.3.11 - with: - fallback: v0.0.0 - drop-prefix: false - prerelease-prefix: dev - prerelease-suffix: "" - prerelease-timestamped: false - - name: Build unstable Alpine x64 image run: | - export REPO_VERSION=${{ steps.use-git-describe-semver.outputs.version }} + export REPO_VERSION=${{ needs.git_describe_semver.outputs.version }} make build-unstable-alpine-buildx64 - name: List generated Docker images @@ -325,6 +311,7 @@ jobs: build_unstable_alpine_x86_image_using_makefile: name: Build unstable Alpine x86 image using Makefile + needs: git_describe_semver runs-on: ubuntu-latest # Default: 360 minutes timeout-minutes: 10 @@ -333,11 +320,8 @@ jobs: - name: Print Docker version run: docker --version - - name: Clone full repo history + - name: Clone repo with default settings uses: actions/checkout@v4 - with: - # Needed in order to retrieve tags for use with semver calculations - fetch-depth: 0 # Mark the current working directory as a safe directory in git to # resolve "dubious ownership" complaints. @@ -354,27 +338,17 @@ jobs: - name: Install Ubuntu packages run: sudo apt-get update && sudo apt-get install -y --no-install-recommends make gcc bsdmainutils - - name: Generate semantic version for project - id: use-git-describe-semver - uses: choffmeister/git-describe-semver@v0.3.11 - with: - fallback: v0.0.0 - drop-prefix: false - prerelease-prefix: dev - prerelease-suffix: "" - prerelease-timestamped: false - - name: Build unstable Alpine x86 image run: | - export REPO_VERSION=${{ steps.use-git-describe-semver.outputs.version }} + export REPO_VERSION=${{ needs.git_describe_semver.outputs.version }} make build-unstable-alpine-buildx86 - name: List generated Docker images run: docker image ls --filter "label=atc0005.go-ci" --format "table {{.Repository}}\t{{.Tag}}\t{{.ID}}\t{{.Size}}" - build_stable_cgo-mingw-w64_image_using_makefile: name: Build stable cgo-mingw-w64 image using Makefile + needs: git_describe_semver runs-on: ubuntu-latest # Default: 360 minutes timeout-minutes: 10 @@ -383,11 +357,8 @@ jobs: - name: Print Docker version run: docker --version - - name: Clone full repo history + - name: Clone repo with default settings uses: actions/checkout@v4 - with: - # Needed in order to retrieve tags for use with semver calculations - fetch-depth: 0 # Mark the current working directory as a safe directory in git to # resolve "dubious ownership" complaints. @@ -404,19 +375,9 @@ jobs: - name: Install Ubuntu packages run: sudo apt-get update && sudo apt-get install -y --no-install-recommends make gcc bsdmainutils - - name: Generate semantic version for project - id: use-git-describe-semver - uses: choffmeister/git-describe-semver@v0.3.11 - with: - fallback: v0.0.0 - drop-prefix: false - prerelease-prefix: dev - prerelease-suffix: "" - prerelease-timestamped: false - - name: Build stable cgo-mingw-w64 image run: | - export REPO_VERSION=${{ steps.use-git-describe-semver.outputs.version }} + export REPO_VERSION=${{ needs.git_describe_semver.outputs.version }} make stable-cgo-mingw-w64-build - name: List generated Docker images @@ -424,6 +385,7 @@ jobs: build_stable_mirror_images_using_makefile: name: Build stable mirror images using Makefile + needs: git_describe_semver runs-on: ubuntu-latest # Default: 360 minutes timeout-minutes: 10 @@ -432,11 +394,8 @@ jobs: - name: Print Docker version run: docker --version - - name: Clone full repo history + - name: Clone repo with default settings uses: actions/checkout@v4 - with: - # Needed in order to retrieve tags for use with semver calculations - fetch-depth: 0 # Mark the current working directory as a safe directory in git to # resolve "dubious ownership" complaints. @@ -453,19 +412,9 @@ jobs: - name: Install Ubuntu packages run: sudo apt-get update && sudo apt-get install -y --no-install-recommends make gcc bsdmainutils - - name: Generate semantic version for project - id: use-git-describe-semver - uses: choffmeister/git-describe-semver@v0.3.11 - with: - fallback: v0.0.0 - drop-prefix: false - prerelease-prefix: dev - prerelease-suffix: "" - prerelease-timestamped: false - - name: Build stable mirror image run: | - export REPO_VERSION=${{ steps.use-git-describe-semver.outputs.version }} + export REPO_VERSION=${{ needs.git_describe_semver.outputs.version }} make stable-mirror-build - name: List generated Docker images @@ -473,6 +422,7 @@ jobs: build_oldstable_image_using_makefile: name: Build oldstable image using Makefile + needs: git_describe_semver runs-on: ubuntu-latest # Default: 360 minutes timeout-minutes: 10 @@ -481,11 +431,8 @@ jobs: - name: Print Docker version run: docker --version - - name: Clone full repo history + - name: Clone repo with default settings uses: actions/checkout@v4 - with: - # Needed in order to retrieve tags for use with semver calculations - fetch-depth: 0 # Mark the current working directory as a safe directory in git to # resolve "dubious ownership" complaints. @@ -502,19 +449,9 @@ jobs: - name: Install Ubuntu packages run: sudo apt-get update && sudo apt-get install -y --no-install-recommends make gcc bsdmainutils - - name: Generate semantic version for project - id: use-git-describe-semver - uses: choffmeister/git-describe-semver@v0.3.11 - with: - fallback: v0.0.0 - drop-prefix: false - prerelease-prefix: dev - prerelease-suffix: "" - prerelease-timestamped: false - - name: Build oldstable image run: | - export REPO_VERSION=${{ steps.use-git-describe-semver.outputs.version }} + export REPO_VERSION=${{ needs.git_describe_semver.outputs.version }} make build-oldstable - name: List generated Docker images @@ -522,6 +459,7 @@ jobs: build_unstable_image_using_makefile: name: Build unstable image using Makefile + needs: git_describe_semver runs-on: ubuntu-latest # Default: 360 minutes timeout-minutes: 10 @@ -530,11 +468,8 @@ jobs: - name: Print Docker version run: docker --version - - name: Clone full repo history + - name: Clone repo with default settings uses: actions/checkout@v4 - with: - # Needed in order to retrieve tags for use with semver calculations - fetch-depth: 0 # Mark the current working directory as a safe directory in git to # resolve "dubious ownership" complaints. @@ -551,19 +486,9 @@ jobs: - name: Install Ubuntu packages run: sudo apt-get update && sudo apt-get install -y --no-install-recommends make gcc bsdmainutils - - name: Generate semantic version for project - id: use-git-describe-semver - uses: choffmeister/git-describe-semver@v0.3.11 - with: - fallback: v0.0.0 - drop-prefix: false - prerelease-prefix: dev - prerelease-suffix: "" - prerelease-timestamped: false - - name: Build unstable image run: | - export REPO_VERSION=${{ steps.use-git-describe-semver.outputs.version }} + export REPO_VERSION=${{ needs.git_describe_semver.outputs.version }} make build-unstable - name: List generated Docker images diff --git a/.github/workflows/release-build.yml b/.github/workflows/release-build.yml index 2997b239..3b8dd7df 100644 --- a/.github/workflows/release-build.yml +++ b/.github/workflows/release-build.yml @@ -10,8 +10,73 @@ on: - "v[0-9]+.[0-9]+.*" jobs: + git_describe_semver: + name: Generate semantic release version using git-describe-semver + runs-on: ubuntu-latest + # Default: 360 minutes + timeout-minutes: 5 + # https://docs.github.com/en/actions/using-jobs/defining-outputs-for-jobs + outputs: + version: ${{ steps.git-describe-semver.outputs.version }} + + steps: + - name: Print Docker version + run: docker --version + + - name: Clone repo with full history + uses: actions/checkout@v4 + with: + # Needed in order to retrieve tags for use with semver calculations + fetch-depth: 0 + + # Mark the current working directory as a safe directory in git to + # resolve "dubious ownership" complaints. + # + # https://docs.github.com/en/actions/learn-github-actions/variables#default-environment-variables + # https://confluence.atlassian.com/bbkb/git-command-returns-fatal-error-about-the-repository-being-owned-by-someone-else-1167744132.html + # https://github.com/actions/runner-images/issues/6775 + # https://github.com/actions/checkout/issues/766 + - name: Mark the current working directory as a safe directory in git + # run: git config --global --add safe.directory "$GITHUB_WORKSPACE" + run: git config --global --add safe.directory "${PWD}" + + # - name: Generate semantic version for project + # id: use-git-describe-semver + # uses: choffmeister/git-describe-semver@v0.3.11 + # with: + # fallback: v0.0.0 + # drop-prefix: false + # prerelease-prefix: dev + # prerelease-suffix: "" + # prerelease-timestamped: false + + # - name: Install git-describe-semver + # id: install-git-describe-semver + # run: go install github.com/choffmeister/git-describe-semver@latest + + # https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#example-of-setting-an-output-parameter + # https://stackoverflow.com/questions/59954185/github-action-split-long-command-into-multiple-lines + - name: Record semantic version using git-describe-semver + id: git-describe-semver + run: > + echo "version=$( + docker container run + --platform linux/amd64 + --rm + -it + -v $PWD:/code + -w /code + ghcr.io/choffmeister/git-describe-semver:0.3.11 + --fallback 'v0.0.0' + --drop-prefix=false + --prerelease-prefix 'dev' + --prerelease-suffix "" + --prerelease-timestamped=false + )" >> "$GITHUB_OUTPUT" + release_build: name: Build and upload container images + needs: git_describe_semver # https://docs.github.com/en/actions/security-guides/automatic-token-authentication permissions: @@ -33,12 +98,8 @@ jobs: echo "Ref full: ${{ github.ref }}" echo "Commit SHA: ${{ github.sha }}" - - name: Check out code (full history) + - name: Check out code with default settings uses: actions/checkout@v4 - with: - # Full history is needed to allow listing tags via build tooling - # (e.g., go-winres, git-describe-semver) - fetch-depth: 0 # Mark the current working directory as a safe directory in git to # resolve "dubious ownership" complaints. @@ -55,25 +116,15 @@ jobs: - name: Install Ubuntu packages run: sudo apt-get update && sudo apt-get install -y --no-install-recommends make gcc bsdmainutils - - name: Generate semantic version for project - id: use-git-describe-semver - uses: choffmeister/git-describe-semver@v0.3.11 - with: - fallback: v0.0.0 - drop-prefix: false - prerelease-prefix: dev - prerelease-suffix: "" - prerelease-timestamped: false - - name: Build all images env: - REPO_VERSION: ${{ steps.use-git-describe-semver.outputs.version }} + REPO_VERSION: ${{ needs.git_describe_semver.outputs.version }} run: | make build - name: Upload all images env: - REPO_VERSION: ${{ steps.use-git-describe-semver.outputs.version }} + REPO_VERSION: ${{ needs.git_describe_semver.outputs.version }} # https://docs.github.com/en/actions/security-guides/encrypted-secrets#using-encrypted-secrets-in-a-workflow DH_TOKEN: ${{ secrets.DOCKERHUB }}