Skip to content

Commit

Permalink
Refactor meta job into separate action
Browse files Browse the repository at this point in the history
  • Loading branch information
alpeb committed Dec 4, 2023
1 parent d45f06f commit c1eb58a
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 59 deletions.
49 changes: 49 additions & 0 deletions .github/actions/version-mode/action.yml
Original file line number Diff line number Diff line change
@@ -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 }}
21 changes: 5 additions & 16 deletions .github/workflows/release-cni-plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}

Expand Down
23 changes: 6 additions & 17 deletions .github/workflows/release-proxy-init.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}

Expand Down
32 changes: 6 additions & 26 deletions .github/workflows/release-validator.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}

Expand Down

0 comments on commit c1eb58a

Please sign in to comment.