From db10d2d79c444815bb5906d5d14bfb2a2809f2ef Mon Sep 17 00:00:00 2001 From: "Jordan K. Wilson" Date: Thu, 16 May 2024 12:57:55 +1200 Subject: [PATCH] feat: allow use of consistent container tagging Adds ability to generate consistent container tag across workflows. --- .github/actions/tagging/action.yml | 28 +++++++++++++++++++++++++++ README.md | 31 ++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 .github/actions/tagging/action.yml diff --git a/.github/actions/tagging/action.yml b/.github/actions/tagging/action.yml new file mode 100644 index 00000000..f505b837 --- /dev/null +++ b/.github/actions/tagging/action.yml @@ -0,0 +1,28 @@ +name: Tagging +description: Consistent and unique container tagging, suitable for immutable tagging +outputs: + relevant-sha: + description: | + Short commit sha based on last commit of pull request, or the last merge commit + value: ${{ steps.tags.outputs.relevant-sha }} + timestamp: + description: | + UTC time of when this action was run + value: ${{ steps.tags.outputs.timestamp }} + tag: + description: | + Recommended container tag, using commit sha, timestamp, and build id + value: + ${{ format('{0}-{1}-{2}', steps.tags.outputs.relevant-sha, steps.tags.outputs.timestamp, github.run_id) }} + +runs: + using: "composite" + steps: + - name: Generate tags + id: tags + env: + RELEVANT_SHA: ${{ github.event.pull_request.head.sha || github.sha }} + shell: bash + run: | + echo "relevant-sha=$(git rev-parse --short $RELEVANT_SHA)" >> $GITHUB_OUTPUT + echo "timestamp=$(date -u +'%Y%m%d%H%M%S')" >> $GITHUB_OUTPUT diff --git a/README.md b/README.md index 8a9ebeb4..1dbe5768 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,8 @@ - [Markdown lint](#markdown-lint) - [Copy to S3](#copy-to-s3) - [Clean container versions](#clean-container-versions) + - [Composite Actions](#composite-actions) + - [Tagging](#tagging) - [Other documentation](#other-documentation) - [Dependabot and Actions workflow imports](#dependabot-and-actions-workflow-imports) - [Versioning for container images](#versioning-for-container-images) @@ -1090,6 +1092,35 @@ jobs: number-kept: 7 ``` +## Composite Actions + +### Tagging + +STATUS: stable + +Generic container tagging. + +Generally will be used in the reusable workflows, but if one needed to use the action directly: + +```yaml +on: [push] + +jobs: + prepare: + runs-on: ubuntu-latest + outputs: + tag: steps.tagging.outputs.tag + steps: + - uses: actions/checkout@v4 + - id: tagging + uses: GeoNet/Actions/.github/actions/tagging@main + build: + needs: prepare + uses: GeoNet/Actions/.github/workflows/reusable-docker-build.yml@main + with: + tag: ${{ needs.prepare.outputs.tag }} +``` + ## Other documentation ### Dependabot and Actions workflow imports