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
8 changes: 7 additions & 1 deletion .github/workflows/publish-action-repo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ concurrency:
jobs:
publish-action-repo:
name: Publish GitHub Action Repository
if: secrets.ACTION_REPO_TOKEN != ''
runs-on: ubuntu-latest
env:
GH_TOKEN: ${{ secrets.ACTION_REPO_TOKEN }}
Expand All @@ -44,6 +43,13 @@ jobs:
ref: ${{ github.event.release.tag_name || inputs.release_tag || github.ref }}
fetch-depth: 0

- name: Validate publication credentials
run: |
if [ -z "${GH_TOKEN}" ]; then
echo "ACTION_REPO_TOKEN is required to publish the GitHub Action repository." >&2
exit 1
fi

- name: Resolve version
id: version
run: |
Expand Down
2 changes: 2 additions & 0 deletions tests/test_action_bundle.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ def test_publish_action_repo_workflow_syncs_action_repository() -> None:
assert "Publish GitHub Action Repository" in workflow_text
assert "ACTION_REPO_TOKEN" in workflow_text
assert "hashgraph-online/hol-codex-plugin-scanner-action" in workflow_text
assert "Validate publication credentials" in workflow_text
assert 'if: secrets.ACTION_REPO_TOKEN != \'\'' not in workflow_text
Comment on lines +37 to +38
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

These new assertions highlight a general issue with this test function: checking for string presence in a structured file like YAML is brittle. For instance, the checks could pass if the string is present in a comment, or fail on benign formatting changes.

A more robust approach is to parse the YAML file and inspect its structure. This makes the test more precise and resilient to formatting changes.

Consider refactoring this test to use a YAML parser (e.g., PyYAML, which would need to be added to test dependencies).

Here's an example of how you could rewrite some of the checks:

import yaml

# In test_publish_action_repo_workflow_syncs_action_repository:
workflow_path = ROOT / ".github" / "workflows" / "publish-action-repo.yml"
workflow_data = yaml.safe_load(workflow_path.read_text(encoding="utf-8"))

# Check workflow name
assert workflow_data["name"] == "Publish GitHub Action Repository"

# Check that the job-level 'if' is removed
# This assumes the job is named 'publish'. Adjust if necessary.
publish_job = workflow_data["jobs"]["publish"]
assert "if" not in publish_job

# Check for the new validation step
step_names = [step.get("name") for step in publish_job["steps"]]
assert "Validate publication credentials" in step_names

# Check for specific commands
all_steps_run_commands = ' '.join([step.get('run', '') for step in publish_job['steps']])
assert 'gh repo create "${ACTION_REPOSITORY}"' in all_steps_run_commands

Applying this pattern to all assertions in this test would significantly improve its maintainability and reliability.

assert 'gh repo create "${ACTION_REPOSITORY}"' in workflow_text
assert 'cp "${GITHUB_WORKSPACE}/action/action.yml" action.yml' in workflow_text
assert 'git push origin refs/tags/v1 --force' in workflow_text
Expand Down
Loading