-
Notifications
You must be signed in to change notification settings - Fork 0
fix: repair main CI and automate action publication #13
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
Merged
+183
−9
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,130 @@ | ||
| name: Publish GitHub Action Repository | ||
|
|
||
| on: | ||
| release: | ||
| types: [published, edited] | ||
| workflow_dispatch: | ||
| inputs: | ||
| release_tag: | ||
| description: "Release tag to publish from the source repository" | ||
| required: false | ||
| default: "" | ||
| action_repository: | ||
| description: "Dedicated public repository that hosts the Marketplace action" | ||
| required: false | ||
| default: "hashgraph-online/hol-codex-plugin-scanner-action" | ||
| create_repository: | ||
| description: "Create the dedicated action repository if it does not exist" | ||
| required: false | ||
| default: true | ||
| type: boolean | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| concurrency: | ||
| group: codex-plugin-scanner-action-publish-${{ github.event.release.tag_name || inputs.release_tag || github.ref }} | ||
| cancel-in-progress: false | ||
|
|
||
| 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 }} | ||
| ACTION_REPOSITORY: ${{ inputs.action_repository != '' && inputs.action_repository || vars.ACTION_REPOSITORY != '' && vars.ACTION_REPOSITORY || 'hashgraph-online/hol-codex-plugin-scanner-action' }} | ||
| RELEASE_TAG: ${{ github.event.release.tag_name || inputs.release_tag }} | ||
| CREATE_REPOSITORY: ${{ github.event_name == 'workflow_dispatch' && inputs.create_repository || 'true' }} | ||
| SOURCE_REPOSITORY: ${{ github.repository }} | ||
| SOURCE_SERVER_URL: ${{ github.server_url }} | ||
| steps: | ||
| - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd | ||
| with: | ||
| ref: ${{ github.event.release.tag_name || inputs.release_tag || github.ref }} | ||
| fetch-depth: 0 | ||
|
|
||
| - name: Resolve version | ||
| id: version | ||
| run: | | ||
| TAG="${RELEASE_TAG}" | ||
| if [ -z "${TAG}" ]; then | ||
| TAG=$(python3 -c "import tomllib; p=tomllib.load(open('pyproject.toml','rb')); print('v' + p['project']['version'])") | ||
| fi | ||
| VERSION="${TAG#v}" | ||
| echo "tag=${TAG}" >> "${GITHUB_OUTPUT}" | ||
| echo "version=${VERSION}" >> "${GITHUB_OUTPUT}" | ||
|
|
||
| - name: Ensure action repository exists | ||
| run: | | ||
| if gh repo view "${ACTION_REPOSITORY}" >/dev/null 2>&1; then | ||
| exit 0 | ||
| fi | ||
| if [ "${CREATE_REPOSITORY}" != "true" ]; then | ||
| echo "Action repository ${ACTION_REPOSITORY} does not exist and automatic creation is disabled." >&2 | ||
| exit 1 | ||
| fi | ||
| gh repo create "${ACTION_REPOSITORY}" \ | ||
| --public \ | ||
| --description "HOL Codex Plugin Scanner GitHub Action" \ | ||
| --homepage "${SOURCE_SERVER_URL}/${SOURCE_REPOSITORY}" \ | ||
| --disable-wiki | ||
|
|
||
| - name: Sync action repository contents | ||
| run: | | ||
| VERSION="${{ steps.version.outputs.version }}" | ||
| TAG="${{ steps.version.outputs.tag }}" | ||
| WORKDIR="${RUNNER_TEMP}/action-repository" | ||
| git clone "https://x-access-token:${GH_TOKEN}@github.com/${ACTION_REPOSITORY}.git" "${WORKDIR}" | ||
| cd "${WORKDIR}" | ||
|
|
||
| if git ls-remote --exit-code origin refs/heads/main >/dev/null 2>&1; then | ||
| git fetch origin main | ||
| git switch -C main origin/main | ||
| else | ||
| git switch --orphan main | ||
| fi | ||
|
|
||
| find . -mindepth 1 -maxdepth 1 ! -name '.git' -exec rm -rf {} + | ||
|
|
||
| cp "${GITHUB_WORKSPACE}/action/action.yml" action.yml | ||
| cp "${GITHUB_WORKSPACE}/action/README.md" README.md | ||
| cp "${GITHUB_WORKSPACE}/LICENSE" LICENSE | ||
| cp "${GITHUB_WORKSPACE}/SECURITY.md" SECURITY.md | ||
|
|
||
| git config user.name "github-actions[bot]" | ||
| git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | ||
| git add action.yml README.md LICENSE SECURITY.md | ||
|
|
||
| HAS_HEAD=true | ||
| git rev-parse --verify HEAD >/dev/null 2>&1 || HAS_HEAD=false | ||
|
|
||
| if [ "${HAS_HEAD}" = "true" ] && git diff --cached --quiet; then | ||
| echo "No action repository content changes detected." | ||
| else | ||
| git commit -m "chore: publish action bundle ${TAG}" | ||
| git push origin HEAD:main | ||
| fi | ||
|
|
||
| git tag -f "${TAG}" | ||
| git push origin "refs/tags/${TAG}" --force | ||
| git tag -f v1 | ||
| git push origin refs/tags/v1 --force | ||
|
|
||
| - name: Create or update action repository release | ||
| run: | | ||
| VERSION="${{ steps.version.outputs.version }}" | ||
| TAG="${{ steps.version.outputs.tag }}" | ||
| NOTES="Published automatically from ${SOURCE_SERVER_URL}/${SOURCE_REPOSITORY}/releases/tag/${TAG}" | ||
|
|
||
| if gh release view "${TAG}" --repo "${ACTION_REPOSITORY}" >/dev/null 2>&1; then | ||
| gh release edit "${TAG}" \ | ||
| --repo "${ACTION_REPOSITORY}" \ | ||
| --title "${TAG}" \ | ||
| --notes "${NOTES}" | ||
| else | ||
| gh release create "${TAG}" \ | ||
| --repo "${ACTION_REPOSITORY}" \ | ||
| --title "${TAG}" \ | ||
| --notes "${NOTES}" | ||
| fi | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
WARNING:
CREATE_REPOSITORYexpression always evaluates to'true'— thecreate_repositoryinput has no effectIn GitHub Actions expressions,
false && <expr> || 'true'always returns'true'because the&&returnsfalse(falsy), then||falls through to the string'true'. When triggered viaworkflow_dispatchwithcreate_repository: false:github.event_name == 'workflow_dispatch'→truetrue && inputs.create_repository→false(boolean input is falsy)false || 'true'→'true'(the fallback always wins)This means the "Create the dedicated action repository if it does not exist" toggle is non-functional — the workflow will always attempt to create the repo.
To fix, coerce the boolean to a string before the
||fallback:A cleaner alternative: use
fromJSON()or a ternary-style pattern like${{ inputs.create_repository == false && 'false' || 'true' }}.