deploy-nightly icon indicating copy to clipboard operation
deploy-nightly copied to clipboard

Check if an asset exists for current commit

Open n-elie opened this issue 5 years ago • 2 comments
trafficstars

Hello,

Would it be possible to use this action to first check if the build is needed? This would save a lot of CI time. For the moment, I have a workflow with the deploy-nightly action but if there is no new commit since last build, the build is still done but not uploaded at the end because the asset already exists.

Regards

n-elie avatar Nov 10 '20 09:11 n-elie

This please

Maxzor avatar Dec 30 '20 12:12 Maxzor

Just in case, some one else has the same problem, I use this job in my workflow to do this check (XXXXXX needs to be replaced by the release id) :

check-assets:
    runs-on: ubuntu-latest
    outputs:
      needs-build: ${{ steps.assets.outputs.needs-build }}
    steps:
      - name: Check existing assets
        id: assets
        run: |
          hash=${{ github.sha }}
          hash=${hash::6}
          names=( $(curl -sL https://api.github.com/repos/${{ github.repository }}/releases/XXXXXX/assets | jq -r '.[].name') )
          needs_build='true'
          if [ "${{ github.event_name }}" == "repository_dispatch" || "${{ github.event_name }}" == "workflow_dispatch" ]; then
            echo "[WARNING] Nightly workflow triggered manually"
          else
            for name in "${names[@]}"
            do
              basename=${name##*-};
              if [ "${basename%.*}" == "$hash" ]; then
                echo "[WARNING] Commit already built, skipping build"
                needs_build='false'
                break
              fi
            done
          fi
          echo "::set-output name=needs-build::$needs_build"

Then I added this job as dependency of the build job:

  build:
    needs: check-assets
    if: needs.check-assets.outputs.needs-build == 'true'

There is also an action made by Maxzor available here: https://github.com/Maxzor/check-nightly

n-elie avatar Jan 04 '21 15:01 n-elie