Skip to content

Commit

Permalink
Trigger publish-to-pypi job when `check-version.outputs.new_version…
Browse files Browse the repository at this point in the history
…` is not empty

PiperOrigin-RevId: 721902917
  • Loading branch information
santoso-wijaya authored and The Meridian Authors committed Jan 31, 2025
1 parent d0c3ed9 commit 3022d6b
Showing 1 changed file with 42 additions and 5 deletions.
47 changes: 42 additions & 5 deletions .github/workflows/pytest_and_autopublish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,51 @@ jobs:
fi
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
create-tag:
name: Create Version Tag
runs-on: ubuntu-latest
needs: check-version
if: ${{ needs.check-version.outputs.new_version != '' }} # Only run if new_version was discovered.
steps:
- uses: actions/checkout@v4
- name: Create and Push Tag
uses: actions/github-script@v6
with:
script: |
const newTag = 'v${{ needs.check-version.outputs.new_version }}';
try {
await github.rest.git.createTag({
owner: context.repo.owner,
repo: context.repo.repo,
tag: newTag,
message: `Release ${newTag}`,
object: context.sha,
type: 'commit'
});
await github.rest.git.createRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: `refs/tags/${newTag}`,
sha: context.sha
});
console.log(`Created and pushed new tag: ${newTag}`);
} catch (error) {
console.error('Error creating tag:', error);
core.setFailed(`Failed to create tag: ${error.message}`);
}
publish-to-pypi:
name: >-
Publish Python distribution to PyPI
name: Publish Python distribution to PyPI
needs: check-version
# Check if it's a tag push or the `publish_to_pypi` workflow is selected in a manual trigger.
if: >
(github.ref_type == 'tag' && startsWith(github.ref, 'refs/tags/'))
|| (github.event_name == 'workflow_dispatch'
&& github.event.inputs.publish_to_pypi == 'true')
github.ref == 'refs/heads/main'
&& (
(github.ref_type == 'tag' && startsWith(github.ref, 'refs/tags/'))
|| (github.event_name == 'workflow_dispatch'
&& github.event.inputs.publish_to_pypi == 'true')
|| needs.check-version.outputs.new_version != ''
)
needs:
- build
- pytest-job
Expand Down

0 comments on commit 3022d6b

Please sign in to comment.