From 9c81a5b0c36a9a53eaa0d20ae803e621061b8961 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Hurlin?= Date: Thu, 18 Apr 2024 12:13:02 +0200 Subject: [PATCH] Support targetting a tag specified as input --- .github/workflows/release-upload.yaml | 98 +++++++++++++++++++-------- 1 file changed, 68 insertions(+), 30 deletions(-) diff --git a/.github/workflows/release-upload.yaml b/.github/workflows/release-upload.yaml index 1ce5e89c3d..4b602c7251 100644 --- a/.github/workflows/release-upload.yaml +++ b/.github/workflows/release-upload.yaml @@ -9,6 +9,12 @@ name: Post Release Upload # from the IOG cache. on: workflow_dispatch: + inputs: + target_tag: + description: 'The tag of the release to attach binaries to' + default: '' + required: false + type: string release: types: - published @@ -16,10 +22,6 @@ on: tags: - '**' env: - # Only to avoid some repetition - # TODO SHOULD BE LIKE THIS: - # FLAKE_REF: github:${{ github.repository }}/${{ github.ref_name }} - FLAKE_REF: github:${{ github.repository }}/6c57ef376ed84fa1d802c49e5aba0f0eac9d2d84 GH_TOKEN: ${{ github.token }} jobs: @@ -27,15 +29,37 @@ jobs: name: "Wait for hydra check-runs" runs-on: ubuntu-latest steps: + - name: Define target tag (1/2) + if: ${{ inputs.target_tag != '' }} # If a tag was specified manually as input, use it + run: | + echo "TARGET_TAG=${{ inputs.target_tag }}" >> "$GITHUB_ENV" + - name: Define target tag (2/2) + if: ${{ inputs.target_tag == '' }} # If no tag was specified manually as input + run: | + current_tag=$(git tag --points-to HEAD | head -n 1) + if [[ "$current_tag" != "" ]] + then + # The workflow runs on a commit that has a tag, use this tag + echo "TARGET_TAG=$current_tag" >> "$GITHUB_ENV" + fi + - name: Check tag is defined + if: ${{ env.TARGET_TAG == '' }} + run: | + echo "The tag to build binaries for is undefined! Either:" + echo "- This pipeline should run on a commit that has a tag" + echo "- This pipeline should be executed manually and the tag to target should be specified with the 'target_tag' input" + exit 1 + - name: Define FLAKE_REF + run: | + flake_ref="github:${{ github.repository }}/${{ env.TARGET_TAG }}" + echo "$flake_ref" + echo "FLAKE_REF=$flake_ref" >> "$GITHUB_ENV" - name: Get specific check run status timeout-minutes: 120 run: | - while [[ true ]]; do - # TODO SHOULD BE LIKE THIS: - # conclusion=$(gh api repos/$GITHUB_REPOSITORY/commits/$GITHUB_SHA/check-runs --jq '.check_runs[] | select(.name == "ci/hydra-build:required") | .conclusion') - # TODO generalize + while true; do # When supporting other architectures than Linux, this query should be adapted: - conclusion=$(gh api repos/$GITHUB_REPOSITORY/commits/6c57ef376ed84fa1d802c49e5aba0f0eac9d2d84/check-runs --jq '.check_runs[] | select(.name | test("ci/hydra-build:.*-linux.required")) | .conclusion') + conclusion=$(gh api "repos/$GITHUB_REPOSITORY/commits/${{ env.TARGET_TAG }}/check-runs" --jq '.check_runs[] | select(.name | test("ci/hydra-build:.*-linux.required")) | .conclusion') case "$conclusion" in success) echo "ci/hydra-build:required succeeded" @@ -66,16 +90,27 @@ jobs: trusted-public-keys = cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= hydra.iohk.io:f/Ea+s+dFdN+3Y/G+FDgSq+a5NEWhJGzdjvKNGv0/EQ= substituters = https://cache.iog.io/ https://cache.nixos.org/ nix_path: nixpkgs=channel:nixos-unstable + - name: LS + run: | + ls + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: LS + run: | + ls - name: Display flake metadata id: flake-metadata run: | nix flake metadata ${{ env.FLAKE_REF }} - nix flake metadata ${{ env.FLAKE_REF }} --json | jq -r '"LOCKED_URL=\(.url)"' >> "$GITHUB_OUTPUT" + nix flake metadata ${{ env.FLAKE_REF }} --json | jq -r '"LOCKED_URL=\(.url)"' >> "$GITHUB_ENV" - name: Build run: | case ${{ matrix.arch }} in linux) - nix build --builders "" --max-jobs 0 ${{ steps.flake-metadata.outputs.LOCKED_URL }}#cardano-cli:exe:cardano-cli + nix build --builders "" --max-jobs 0 ${{ env.LOCKED_URL }}#cardano-cli:exe:cardano-cli + tree result/bin cp result/bin/cardano-cli cardano-cli-${{ matrix.arch }} ;; # TODO generalize @@ -90,31 +125,34 @@ jobs: # tree result # ;; esac - - uses: actions/upload-artifact@v3 + - uses: actions/upload-artifact@v4 with: name: ${{ github.sha }}-${{ matrix.arch }} path: cardano-cli-* retention-days: 1 - # upload-assets: - # needs: [pull] - # name: "Upload Assets" - # runs-on: ubuntu-latest - # steps: - # - uses: actions/download-artifact@v3 - # with: - # name: ${{ github.sha }}-linux - # - uses: actions/download-artifact@v3 + upload-assets: + needs: [pull] + name: "Upload Assets" + runs-on: ubuntu-latest + steps: + - uses: actions/download-artifact@v4 + with: + name: ${{ github.sha }}-linux + # TODO generalize + # - uses: actions/download-artifact@v4 # with: # name: ${{ github.sha }}-macos - # - uses: actions/download-artifact@v3 + # - uses: actions/download-artifact@v4 # with: # name: ${{ github.sha }}-win64 - # - name: Release - # uses: input-output-hk/action-gh-release@v1 - # with: - # draft: true - # files: | - # cardano-node-*-win64.zip - # cardano-node-*-macos.tar.gz - # cardano-node-*-linux.tar.gz + - name: Release + uses: input-output-hk/action-gh-release@v1 + with: + draft: true + tag_name: ${{ env.TARGET_TAG }} + files: | + # TODO generalize + # cardano-cli-*-win64.zip + # cardano-cli-*-macos.tar.gz + cardano-cli-*-linux.tar.gz