Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: upload collection artifact to GH release #327

Merged
merged 2 commits into from
Sep 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions .github/workflows/tox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -269,7 +273,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