diff --git a/.github/workflows/test-setup-argo.yml b/.github/workflows/test-setup-argo.yml new file mode 100644 index 000000000..c24809903 --- /dev/null +++ b/.github/workflows/test-setup-argo.yml @@ -0,0 +1,57 @@ +name: Test Setup Argo +on: + push: + branches: + - main + paths: + - actions/setup-argo/** + - .github/workflows/test-setup-argo.yml + + pull_request: + branches: + - main + paths: + - actions/setup-argo/** + - .github/workflows/test-setup-argo.yml + merge_group: + +concurrency: + group: "${{ github.workflow }}-${{ github.ref }}" + cancel-in-progress: true + +jobs: + setup-argo: + runs-on: ubuntu-latest + env: + # generate a unique cache prefix for each test run, so we can test cache behaviour + CACHE_PREFIX: argo-${{ github.run_id }}-${{ github.run_attempt }} + + strategy: + matrix: + cache-hit: [false, true] + max-parallel: 1 + + name: "Setup Argo (cache hit: ${{ matrix.cache-hit }})" + + steps: + - name: Checkout code + uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + with: + sparse-checkout: | + actions/setup-argo + + - name: "Setup Argo (cache: ${{ matrix.cache-hit }})" + id: setup-argo + uses: ./actions/setup-argo + with: + cache-prefix: ${{ env.CACHE_PREFIX }} + version: 3.5.1 + + - name: Assert cache + if: fromJson(steps.setup-argo.outputs.cache-hit) != matrix.cache-hit + run: | + echo "Expected cache hit: '${{ matrix.cache-hit }}' but got '${{ fromJson(steps.setup-argo.outputs.cache-hit) }}'" + exit 1 + + - name: Check Argo CLI works + run: argo version diff --git a/actions/setup-argo/action.yaml b/actions/setup-argo/action.yaml index 6d797e4c8..1fe560ae9 100644 --- a/actions/setup-argo/action.yaml +++ b/actions/setup-argo/action.yaml @@ -2,11 +2,20 @@ name: Setup Argo description: Setup Argo cli and add it to the PATH, this action will pull the binary from GitHub releases and store it in cache for the next run. inputs: + cache-prefix: + description: Prefix for the cache key. + default: argo + version: description: | Version of the Argo CLI to install. default: 3.5.1 +outputs: + cache-hit: + description: Whether the cache was hit or not. + value: ${{ steps.cache.outputs.cache-hit || 'false' }} + runs: using: composite @@ -16,10 +25,11 @@ runs: uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2 with: path: ${{ github.workspace }}/bin/argo - key: argo-${{ runner.os }}-${{ runner.arch }}-${{ inputs.version }} + key: ${{ inputs.cache-prefix }}-${{ runner.os }}-${{ runner.arch }}-${{ inputs.version }} - name: Normalize runner.os to match Argo release - shell: sh + if: steps.cache.outputs.cache-hit != 'true' + shell: bash env: OS: ${{ runner.os }} run: | @@ -30,17 +40,17 @@ runs: # runner.arch options: X86, X64, ARM, or ARM64. # argo release: arm64, amd64, ppc64le, s390x. # If it ain't arm64 or amd64, it'll fall back to runner.arch. - - if: runner.arch == 'X64' + - if: runner.arch == 'X64' && steps.cache.outputs.cache-hit != 'true' shell: sh run: echo "ARCH=amd64" >> "$GITHUB_ENV" - - if: runner.arch == 'ARM64' + - if: runner.arch == 'ARM64' && steps.cache.outputs.cache-hit != 'true' shell: sh run: echo "ARCH=arm64" >> "$GITHUB_ENV" - name: Fetch Github Release Asset id: fetch_asset - if: steps.restore.outputs.cache-hit != 'true' + if: steps.cache.outputs.cache-hit != 'true' uses: dsaltares/fetch-gh-release-asset@a40c8b4a0471f9ab81bdf73a010f74cc51476ad4 # 1.1.1 with: repo: "argoproj/argo-workflows" @@ -53,10 +63,19 @@ runs: if: steps.fetch_asset.outcome == 'success' shell: sh run: | - gunzip ${{ github.workspace }}/bin/argo.gz + # Overwrite the argo binary if it already exists. We assume it's from a + # previous run of this action. + gunzip --force ${{ github.workspace }}/bin/argo.gz chmod +x ${{ github.workspace }}/bin/argo - name: Add binary to path shell: sh run: | - echo "${{ github.workspace }}/bin" >> $GITHUB_PATH + # Check if `argo` is already in the PATH + if command -v argo >/dev/null; then + echo "argo is already in the PATH, not re-adding it" + exit 0 + fi + + echo "Adding '${{ github.workspace }}/bin' to the PATH so the 'argo' binary can be found" + echo "${{ github.workspace }}/bin" >> "${GITHUB_PATH}"