From c1eb58add0f3a816254cd2d8579efdf5cf8cee5b Mon Sep 17 00:00:00 2001 From: Alejandro Pedraza Date: Mon, 4 Dec 2023 13:37:38 -0500 Subject: [PATCH] Refactor meta job into separate action --- .github/actions/version-mode/action.yml | 49 ++++++++++++++++++++++++ .github/workflows/release-cni-plugin.yml | 21 +++------- .github/workflows/release-proxy-init.yml | 23 +++-------- .github/workflows/release-validator.yml | 32 +++------------- 4 files changed, 66 insertions(+), 59 deletions(-) create mode 100644 .github/actions/version-mode/action.yml diff --git a/.github/actions/version-mode/action.yml b/.github/actions/version-mode/action.yml new file mode 100644 index 00000000..24d54b2b --- /dev/null +++ b/.github/actions/version-mode/action.yml @@ -0,0 +1,49 @@ +name: Version and mode +description: Declare package version and mode + +inputs: + package: + required: true + check: + required: false + default: false + +runs: + using: composite + steps: + - uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac + - id: meta + shell: bash + run: | + set -eu + shopt -s extglob + ref="${{ github.ref }}" + if [[ "$ref" == refs/tags/${{ inputs.package }}/v+([0-9]).+([0-9]).+([0-9])?(-+([a-z0-9-])) ]]; then + ( echo version="${ref##refs/tags/${{ inputs.package }}/}" + echo mode=release + ) >> "$GITHUB_OUTPUT" + else + sha="${{ github.sha }}" + ( echo version="test-${sha:0:7}" + echo mode=test + ) >> "$GITHUB_OUTPUT" + fi + echo "repo=ghcr.io/${{ github.repository_owner }}/${{ inputs.package }}" + - if: steps.meta.outputs.mode == 'release' && inputs.check == 'true' + name: Check that version matches release version + shell: bash + run: | + version=$(just ${{ inputs.package }} --evaluate version) + # shellcheck disable=SC2193 + if [[ "${version}" != '${{ steps.meta.outputs.version }}' ]]; then + echo "::error ::Crate version v${version} does not match tag ${{ steps.meta.outputs.version }}" + exit 1 + fi + +outputs: + mode: + value: ${{ steps.meta.outputs.mode }} + version: + value: ${{ steps.meta.outputs.version }} + repo: + value: ${{ steps.meta.outputs.repo }} diff --git a/.github/workflows/release-cni-plugin.yml b/.github/workflows/release-cni-plugin.yml index 91156fc2..7e29fefe 100644 --- a/.github/workflows/release-cni-plugin.yml +++ b/.github/workflows/release-cni-plugin.yml @@ -15,24 +15,13 @@ jobs: timeout-minutes: 3 runs-on: ubuntu-latest steps: + - uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac - id: meta - shell: bash - run: | - set -eu - shopt -s extglob - ref='${{ github.ref }}' - if [[ "$ref" == refs/tags/cni-plugin/v+([0-9]).+([0-9]).+([0-9])?(-+([a-z0-9-])) ]]; then - ( echo version="${ref##refs/tags/cni-plugin/}" - echo mode=release - ) >> "$GITHUB_OUTPUT" - else - sha='${{ github.sha }}' - ( echo version="test-${sha:0:7}" - echo mode=test - ) >> "$GITHUB_OUTPUT" - fi + uses: ./.github/actions/version-mode + with: + package: cni-plugin outputs: - repo: ghcr.io/${{ github.repository_owner }}/cni-plugin + repo: ${{ steps.meta.outputs.repo }} mode: ${{ steps.meta.outputs.mode }} version: ${{ steps.meta.outputs.version }} diff --git a/.github/workflows/release-proxy-init.yml b/.github/workflows/release-proxy-init.yml index 6c648aa1..414c4939 100644 --- a/.github/workflows/release-proxy-init.yml +++ b/.github/workflows/release-proxy-init.yml @@ -15,24 +15,13 @@ jobs: timeout-minutes: 3 runs-on: ubuntu-latest steps: - - id: meta - shell: bash - run: | - set -eu - shopt -s extglob - ref='${{ github.ref }}' - if [[ "$ref" == refs/tags/proxy-init/v+([0-9]).+([0-9]).+([0-9])?(-+([a-z0-9-])) ]]; then - ( echo version="${ref##refs/tags/proxy-init/}" - echo mode=release - ) >> "$GITHUB_OUTPUT" - else - sha='${{ github.sha }}' - ( echo version="test-${sha:0:7}" - echo mode=test - ) >> "$GITHUB_OUTPUT" - fi + - uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac + - uses: ./.github/actions/version-mode + id: meta + with: + package: proxy-init outputs: - repo: ghcr.io/${{ github.repository_owner }}/proxy-init + repo: ${{ steps.meta.outputs.repo }} mode: ${{ steps.meta.outputs.mode }} version: ${{ steps.meta.outputs.version }} diff --git a/.github/workflows/release-validator.yml b/.github/workflows/release-validator.yml index 6900f1ce..95205c5f 100644 --- a/.github/workflows/release-validator.yml +++ b/.github/workflows/release-validator.yml @@ -17,33 +17,13 @@ jobs: container: ghcr.io/linkerd/dev:v42-rust steps: - uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac - - id: meta - shell: bash - run: | - set -eu - shopt -s extglob - ref="${{ github.ref }}" - if [[ "$ref" == refs/tags/validator/v+([0-9]).+([0-9]).+([0-9])?(-+([a-z0-9-])) ]]; then - ( echo version="${ref##refs/tags/validator/}" - echo mode=release - ) >> "$GITHUB_OUTPUT" - else - sha="${{ github.sha }}" - ( echo version="$(just validator --evaluate version)-${sha:0:7}" - echo mode=test - ) >> "$GITHUB_OUTPUT" - fi - - if: steps.meta.outputs.mode == 'release' - name: Check that validator version matches release version - shell: bash - run: | - version=$(just validator --evaluate version) - # shellcheck disable=SC2193 - if [[ "${version}" != '${{ steps.meta.outputs.version }}' ]]; then - echo "::error ::Crate version v${version} does not match tag ${{ steps.meta.outputs.version }}" - exit 1 - fi + - uses: ./.github/actions/version-mode + id: meta + with: + package: validator + check: true outputs: + repo: ${{ steps.meta.outputs.repo }} mode: ${{ steps.meta.outputs.mode }} version: ${{ steps.meta.outputs.version }}