From af6ccdbde5a92362bda5bcf545defcfc7ac4cbb8 Mon Sep 17 00:00:00 2001 From: Hao Liu <44379968+TheRealHaoLiu@users.noreply.github.com> Date: Tue, 28 May 2024 15:27:34 -0400 Subject: [PATCH] Fix galaxy publishing (#15233) - switch to galaxy search API for determining if the version we want to publish already exist - switch from github action variable to env var for easier copy and paste testing --- .github/workflows/promote.yml | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/.github/workflows/promote.yml b/.github/workflows/promote.yml index 76a3194724..604485d328 100644 --- a/.github/workflows/promote.yml +++ b/.github/workflows/promote.yml @@ -60,15 +60,18 @@ jobs: COLLECTION_VERSION: ${{ env.TAG_NAME }} COLLECTION_TEMPLATE_VERSION: true run: | + sudo apt-get install jq make build_collection - curl_with_redirects=$(curl --head -sLw '%{http_code}' https://galaxy.ansible.com/download/${{ env.collection_namespace }}-awx-${{ env.TAG_NAME }}.tar.gz | tail -1) - curl_without_redirects=$(curl --head -sw '%{http_code}' https://galaxy.ansible.com/download/${{ env.collection_namespace }}-awx-${{ env.TAG_NAME }}.tar.gz | tail -1) - if [[ "$curl_with_redirects" == "302" ]] || [[ "$curl_without_redirects" == "302" ]]; then + count=$(curl -s https://galaxy.ansible.com/api/v3/plugin/ansible/search/collection-versions/\?namespace\=${COLLECTION_NAMESPACE}\&name\=awx\&version\=${COLLECTION_VERSION} | jq .meta.count) + if [[ "$count" == "1" ]]; then echo "Galaxy release already done"; - else + elif [[ "$count" == "0" ]]; then ansible-galaxy collection publish \ --token=${{ secrets.GALAXY_TOKEN }} \ - awx_collection_build/${{ env.collection_namespace }}-awx-${{ env.TAG_NAME }}.tar.gz; + awx_collection_build/${COLLECTION_NAMESPACE}-awx-${COLLECTION_VERSION}.tar.gz; + else + echo "Unexpected count from galaxy search: $count"; + exit 1; fi - name: Set official pypi info