Repository navigation
fix: make Galaxy collection publish idempotent #106
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,10 +16,10 @@ jobs: | |
| matrix: | ||
| collection: [cloud, crypto] | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| - uses: actions/checkout@v7 | ||
|
|
||
| - name: Set up Python | ||
| uses: actions/setup-python@v5 | ||
| uses: actions/setup-python@v7 | ||
| with: | ||
| python-version: "3.x" | ||
|
|
||
|
|
@@ -31,10 +31,22 @@ jobs: | |
| env: | ||
| GALAXY_API_KEY: ${{ secrets.GALAXY_API_KEY }} | ||
| run: | | ||
| if [ -z "$GALAXY_API_KEY" ]; then | ||
| set -euo pipefail | ||
| if [ -z "${GALAXY_API_KEY:-}" ]; then | ||
| echo "GALAXY_API_KEY secret is not set" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| version=$(awk '/^version:/ {print $2; exit}' galaxy.yml) | ||
| echo "galaxy.yml version=${version}" | ||
|
|
||
| # Skip if this version is already on Galaxy (idempotent on re-push) | ||
| api="https://galaxy.ansible.com/api/v3/plugin/ansible/content/published/collections/index/o1labs/${{ matrix.collection }}/versions/${version}/" | ||
| if curl -fsSIL "$api" >/dev/null 2>&1; then | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win 🔎 Supported by static analysis🏁 Script executed: #!/bin/bash
set -eu
printf '%s\n' '--- workflow ---'
cat -n .github/workflows/galaxy-collection-publish.yml | sed -n '1,95p'
printf '%s\n' '--- related references ---'
rg -n -S 'api\.ansible\.com|galaxy-ng|collection publish|curl .*HEAD|curl .*http_code|persist-credentials' .github README.md galaxy.yml collections 2>/dev/null || trueRepository: O1ahmad/operator Length of output: 2297 🌐 Web query:
💡 Result: The Ansible Galaxy NG API v3 endpoint for listing collection versions is: GET /api/v3/plugin/ansible/content/published/collections/index/{namespace}/{name}/versions/ [1][2] This endpoint is part of the Galaxy NG API v3, which serves as a primary interface for content consumption, including support for the ansible-galaxy CLI [3]. Parameters for this endpoint include: - namespace (path): The namespace of the collection [1][2] - name (path): The name of the collection [1][2] - limit (query, optional): The number of results to return [1][2] - offset (query, optional): The offset into the results [1][2] - is_highest (query, optional): Filter to only return the highest version of the collection [1][2] - ordering (query, optional): A comma-separated list of fields to order the results by (e.g., version, pulp_created) [1][2] - tags (query, optional): A comma-separated list of tags to filter results [1][2] - fields (query, optional): A comma-separated list of fields to include in the response [1][2] - exclude_fields (query, optional): A comma-separated list of fields to exclude from the response [1][2] The HEAD method is typically supported for this path as part of standard REST API design to retrieve resource metadata without the full response body, though documentation primarily highlights the GET operation for listing versions [1][2]. Users interact with this API to fetch collection metadata required for tasks such as installing collections via the Ansible CLI [4][3]. Citations:
🌐 Web query:
💡 Result: In curl, the interplay between the --fail and --head options, along with how exit statuses and transport errors are handled, is defined as follows: --fail (-f) When using HTTP, this option tells curl to fail silently—meaning it does not output the server's error document (body)—if the server returns an HTTP response code of 400 or greater [1][2]. In these cases, curl returns exit code 22 [1][3]. By default, curl does not treat HTTP error codes as failures and will output the response body even for 4xx or 5xx statuses [1][2]. --head (-I) This option requests only the header portion of the response from the server (using the HTTP HEAD method) [4][5]. When combined with --fail, curl will check the HTTP status code returned in the header [1][2]. If that status code is 400 or higher, the --fail option will trigger, causing curl to exit with code 22, while outputting only the headers it received [1][2]. Exit Status and Transport Errors Curl uses specific exit codes to indicate the nature of a failure [6]. - Exit code 22 is explicitly associated with the --fail option when an HTTP server returns a 400+ status code [6]. - Transport errors (e.g., DNS failure, connection refused, or the server closing the connection unexpectedly) are separate from HTTP status code errors [6]. Even without --fail, curl will return a non-zero exit code if a transport-level error occurs [6]. - If multiple URLs are provided and one fails, curl's default behavior is to continue with subsequent URLs [7][1]. The --fail-early option can be used to ensure curl exits immediately upon the first detected transfer error, preventing later transfers from potentially obscuring the initial failure [7][1]. Note that --fail is not global, so if you are using --next to perform multiple distinct operations, --fail must be specified for each operation where you want the 400+ status check to apply [7][2]. Alternative options include --fail-with-body, which causes curl to exit with code 22 on 400+ errors while still allowing the response body to be output [7][1]. Citations:
Fail closed when Galaxy cannot answer the version check. At 🧰 Tools🪛 zizmor (1.29.0)[warning] 12-53: overly broad permissions (excessive-permissions): default permissions used due to no permissions: block (excessive-permissions) 🤖 Prompt for AI AgentsSource: MCP tools |
||
| echo "o1labs.${{ matrix.collection }}:${version} already published; skipping" | ||
| exit 0 | ||
| fi | ||
|
|
||
| ansible-galaxy collection build --force | ||
| tarball=$(ls -1 o1labs-${{ matrix.collection }}-*.tar.gz | head -1) | ||
| ansible-galaxy collection publish "$tarball" --api-key "$GALAXY_API_KEY" | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔒 Security & Privacy | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
Repository: O1ahmad/operator
Length of output: 2170
🌐 Web query:
actions/checkout v7 persist-credentials default true token stored local git config💡 Result:
In actions/checkout v7, the persist-credentials input has a default value of true [1][2]. Starting with v6.0.0, the mechanism for persisting these credentials was updated to improve security [3]. Rather than writing the token or SSH key directly into the main.git/config file, the action now saves the credentials to a separate file and uses Git's includeIf directive to load them [3]. This change was implemented to better isolate sensitive credentials and prevent them from being easily exposed in contexts where the main configuration file might be read [4][3]. The credentials are removed during the post-job cleanup process [5][6]. If you wish to prevent the action from configuring these credentials, you can explicitly set persist-credentials: false in your workflow step [5][7].
Citations:
Sensitive Data Exposure (CWE-522): Insufficiently Protected Credentials
Reachability: External · Exploitability: Difficult
Disable checkout credential persistence for this job.
No later step uses authenticated Git operations. Set
persist-credentials: falseso checkout does not configureGITHUB_TOKENfor later commands.Proposed fix
📝 Committable suggestion
🧰 Tools
🪛 zizmor (1.29.0)
[warning] 19-19: credential persistence through GitHub Actions artifacts (artipacked): does not set persist-credentials: false
(artipacked)
[warning] 12-53: overly broad permissions (excessive-permissions): default permissions used due to no permissions: block
(excessive-permissions)
🤖 Prompt for AI Agents
Sources: MCP tools, Linters/SAST tools