diff --git a/.github/workflows/update-latest-image-label.yml b/.github/workflows/update-latest-image-label.yml index 9cf024a4..279a663c 100644 --- a/.github/workflows/update-latest-image-label.yml +++ b/.github/workflows/update-latest-image-label.yml @@ -16,9 +16,14 @@ jobs: - name: Get latest package version id: latest-version run: | - VERSION=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" https://api.github.com/user/packages/container/crank/versions | jq -r '.[0].metadata.container.tags[0]') - echo "::set-output name=version::$VERSION" + JSON_RESPONSE=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" https://api.github.com/user/packages/container/crank/versions) + if [ $(echo $JSON_RESPONSE | jq '. | length') -gt 0 ] && [ $(echo $JSON_RESPONSE | jq '.[0].metadata.container.tags | length') -gt 0 ]; then + VERSION=$(echo $JSON_RESPONSE | jq -r '.[0].metadata.container.tags[0]') + echo "::set-output name=version::$VERSION" + fi - name: Update latest label run: | - curl -X POST -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" -H "Accept: application/vnd.github.v3+json" https://api.github.com/user/packages/container/crank/versions/${{ steps.latest-version.outputs.version }}/labels -d '{"labels": ["latest"]}' \ No newline at end of file + if [ -n "${{ steps.latest-version.outputs.version }}" ]; then + curl -X POST -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" -H "Accept: application/vnd.github.v3+json" https://api.github.com/user/packages/container/crank/versions/${{ steps.latest-version.outputs.version }}/labels -d '{"labels": ["latest"]}' + fi \ No newline at end of file