From bf5647d6dfd0a787f2107beb291a7acbbebe80f7 Mon Sep 17 00:00:00 2001 From: Alex Date: Tue, 17 Sep 2024 13:21:47 +0200 Subject: [PATCH] ci: upload collection artifact to GH release Signed-off-by: Alex --- .github/workflows/tox.yml | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/.github/workflows/tox.yml b/.github/workflows/tox.yml index 5d91738d..40d32452 100644 --- a/.github/workflows/tox.yml +++ b/.github/workflows/tox.yml @@ -254,6 +254,10 @@ jobs: with: name: collection-artifact + - name: Set tarball as environment variable + id: set_tarball + run: echo "TARBALL=$(ls -1 ./*.tar.gz)" >> $GITHUB_ENV + - name: Setup python uses: actions/setup-python@v5 with: @@ -267,7 +271,23 @@ jobs: [[ "${{ secrets.ANSIBLE_GALAXY_API_KEY != '' }}" ]] || { echo "ANSIBLE_GALAXY_API_KEY is required to publish on galaxy" ; exit 1; } - TARBALL=$(ls -1 ./*.tar.gz) - - ansible-galaxy collection publish "${TARBALL}" --api-key "${{ + ansible-galaxy collection publish "${{ env.TARBALL }}" --api-key "${{ secrets.ANSIBLE_GALAXY_API_KEY }}" + + - name: Upload the artifact to the release + if: github.ref_type == 'tag' + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + TAG_NAME=$(echo ${{ github.ref }} | sed 's/refs\/tags\///') + + # Check if a release exists for the current tag + RELEASE_EXISTS=$(gh release view $TAG_NAME --json id --jq '.id' || echo "no_release") + + # If a release exists, upload the artifact + if [ "$RELEASE_EXISTS" != "no_release" ]; then + echo "Release found for tag $TAG_NAME. Uploading artifact." + gh release upload $TAG_NAME "${{ env.TARBALL }}" + else + echo "No release found for tag $TAG_NAME. Skipping artifact upload." + fi