Skip to content
Merged
Show file tree
Hide file tree
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
49 changes: 42 additions & 7 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ on:
version:
description: "Version number to release"
required: true
overwrite_existing:
description: "Overwrite version if already published to Galaxy"
required: false
type: boolean
default: false

concurrency:
group: release-${{ github.ref }}
Expand All @@ -24,6 +29,7 @@ jobs:
contents: write # Required for creating releases and tags
env:
VERSION: ${{ github.event.inputs.version }} # zizmor: ignore[template-injection] -- User input is required for this workflow
OVERWRITE_EXISTING: ${{ github.event.inputs.overwrite_existing }} # zizmor: ignore[template-injection] -- Boolean input is safe for this comparison
GHP_BASE_URL: https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}
GALAXY_API_KEY: ${{ secrets.GALAXY_API_KEY }} # zizmor: ignore[secrets-outside-env] -- Galaxy API key needed for publishing; workflow_dispatch only
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # zizmor: ignore[secrets-outside-env] -- GitHub token needed for release creation; workflow_dispatch only
Expand All @@ -41,11 +47,43 @@ jobs:
- name: Install PyYaml
run: pip install pyyaml

- name: Validate version matches galaxy.yml
run: |
GALAXY_VERSION=$(python -c "import yaml; print(yaml.safe_load(open('galaxy.yml'))['version'])")
if [ "${GALAXY_VERSION}" != "${VERSION}" ]; then
echo "::error::Input version '${VERSION}' does not match galaxy.yml version '${GALAXY_VERSION}'."
exit 1
fi
echo "Version ${VERSION} matches galaxy.yml"

- name: Check if version exists on Galaxy
id: check_galaxy_version
run: |
if curl --head -s -f -o /dev/null "https://galaxy.ansible.com/download/lowlydba-sqlserver-${VERSION}.tar.gz"; then
echo "exists=true" >> "$GITHUB_OUTPUT"
echo "Version ${VERSION} already exists on Galaxy"
else
echo "exists=false" >> "$GITHUB_OUTPUT"
echo "Version ${VERSION} does not yet exist on Galaxy"
Comment on lines +62 to +67
Copy link

Copilot AI Apr 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Galaxy existence check treats any curl failure (network/DNS/timeout/5xx) the same as “version does not exist” and proceeds, which can lead to attempting a publish/release under uncertain Galaxy availability. Consider capturing the HTTP status explicitly and only treating 404 as “does not exist”; for other non-success statuses or curl transport errors, fail the job so the release isn’t created based on a false negative.

Suggested change
if curl --head -s -f -o /dev/null "https://galaxy.ansible.com/download/lowlydba-sqlserver-${VERSION}.tar.gz"; then
echo "exists=true" >> "$GITHUB_OUTPUT"
echo "Version ${VERSION} already exists on Galaxy"
else
echo "exists=false" >> "$GITHUB_OUTPUT"
echo "Version ${VERSION} does not yet exist on Galaxy"
GALAXY_URL="https://galaxy.ansible.com/download/lowlydba-sqlserver-${VERSION}.tar.gz"
if HTTP_STATUS=$(curl --head -s -o /dev/null -w "%{http_code}" "${GALAXY_URL}"); then
case "${HTTP_STATUS}" in
200)
echo "exists=true" >> "$GITHUB_OUTPUT"
echo "Version ${VERSION} already exists on Galaxy"
;;
404)
echo "exists=false" >> "$GITHUB_OUTPUT"
echo "Version ${VERSION} does not yet exist on Galaxy"
;;
*)
echo "::error::Unexpected HTTP status ${HTTP_STATUS} while checking whether version ${VERSION} exists on Galaxy."
exit 1
;;
esac
else
echo "::error::Failed to query Galaxy for version ${VERSION}."
exit 1

Copilot uses AI. Check for mistakes.
fi

- name: Abort if version exists and overwrite not enabled
if: steps.check_galaxy_version.outputs.exists == 'true' && env.OVERWRITE_EXISTING != 'true'
run: |
echo "::error::Version ${VERSION} already exists on Galaxy. Set overwrite_existing=true to overwrite."
exit 1

- name: Publish to Galaxy
uses: artis3n/ansible_galaxy_collection@ffbca2460a5a1c600b941bbf1536bd61de1c2227 # v3.0.0
with:
api_key: ${{ env.GALAXY_API_KEY }}

- name: Upload collection artifact
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: lowlydba-sqlserver-${{ env.VERSION }}
path: ${{ github.workspace }}/lowlydba-sqlserver-${{ env.VERSION }}.tar.gz

- name: Validate version is published to Galaxy
run: curl --head -s -f -o /dev/null "https://galaxy.ansible.com/download/lowlydba-sqlserver-${VERSION}.tar.gz"

Expand Down Expand Up @@ -87,10 +125,7 @@ jobs:
e.write("RELEASE_DESCRIPTION<<EOF\n%s\nEOF" % description)

- name: Create Release
id: create_release
uses: softprops/action-gh-release@153bb8e04406b158c6c84fc1615b65b24149a1fe # zizmor: ignore[superfluous-actions] -- Using action for release creation provides better GitHub API integration and version tagging features
with:
token: ${{ env.GITHUB_TOKEN }}
tag_name: ${{ env.VERSION }}
name: ${{ env.VERSION }}
body: ${{ env.RELEASE_DESCRIPTION }}
run: |
gh release create "${VERSION}" \
--title "${VERSION}" \
--notes "${RELEASE_DESCRIPTION}"
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,13 @@ def exec_command(self, cmd, in_data=None, sudoable=True):

display.debug("in local_pwsh.exec_command()")

# mac (darwin) has different pwsh install location than linux
if sys.platform.startswith('darwin'):
executable = '/usr/local/bin/pwsh'
else:
executable = '/usr/bin/pwsh'
# executable = C.DEFAULT_EXECUTABLE.split()[0] if C.DEFAULT_EXECUTABLE else None
# Locate pwsh dynamically; fall back to platform-specific defaults
executable = shutil.which('pwsh')
if executable is None:
if sys.platform.startswith('darwin'):
executable = '/usr/local/bin/pwsh'
else:
executable = '/usr/bin/pwsh'

if not os.path.exists(to_bytes(executable, errors='surrogate_or_strict')):
raise AnsibleError("failed to find the executable specified %s."
Expand Down
Loading