Repository navigation
ci: automate releases, BCR publishing, and API documentation #110
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
+640
−14
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
55f247f
ci: automate releases and BCR publishing
dcarp ca9386b
feat: generate API documentation for releases
dcarp 63fbfeb
ci: require pre-commit checks
dcarp 3e6dca4
fix: use public C++ toolchain helpers for Bazel 10 compatibility
dcarp efbf63c
ci: add conclusion check with legacy aliases
dcarp a13ef2c
ci: adopt release-please for release automation
dcarp 78bbd47
ci: validate Conventional Commit PR titles
dcarp 5a8955d
style: sort Mojo library load symbols
dcarp 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,16 @@ | ||
| { | ||
| "homepage": "https://github.com/modular/rules_mojo", | ||
| "maintainers": [ | ||
| { | ||
| "email": "atrotta@modular.com", | ||
| "github": "Ahajha", | ||
| "name": "Alex Trotta", | ||
| "github_user_id": 44127594 | ||
| } | ||
| ], | ||
| "repository": [ | ||
| "github:modular/rules_mojo" | ||
| ], | ||
| "versions": [], | ||
| "yanked_versions": {} | ||
| } |
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,12 @@ | ||
| bcr_test_module: | ||
| module_path: '.' | ||
| matrix: | ||
| bazel: ['8.x', '9.x', '10.*'] | ||
| platform: ['macos_arm64', 'ubuntu2204', 'ubuntu2404_arm64'] | ||
| tasks: | ||
| run_tests: | ||
| name: 'Run test module' | ||
| bazel: ${{ bazel }} | ||
| platform: ${{ platform }} | ||
| test_targets: | ||
| - '//...' |
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,8 @@ | ||
| { | ||
| "integrity": "", | ||
| "strip_prefix": "rules_mojo-{VERSION}", | ||
| "url": "https://github.com/{OWNER}/{REPO}/releases/download/{TAG}/rules_mojo-{VERSION}.tar.gz", | ||
| "docs_url": "https://github.com/{OWNER}/{REPO}/releases/download/{TAG}/rules_mojo-{VERSION}.docs.tar.gz", | ||
| "patch_strip": 1, | ||
| "patches": {} | ||
| } |
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,19 @@ | ||
| #!/usr/bin/env bash | ||
| set -euo pipefail | ||
|
|
||
| # Print only the requested version, accepting linked and plain release headings. | ||
| # An optional path lets validation inspect the tagged changelog before checkout. | ||
| TAG=${1:?Usage: changelog_entry.sh <unprefixed-release-tag> [changelog-path]} | ||
| CHANGELOG=${2:-CHANGELOG.md} | ||
| if [[ -f "$CHANGELOG" ]]; then | ||
| awk -v version="$TAG" ' | ||
| /^##? / { | ||
| heading = $2 | ||
| sub(/^\[/, "", heading) | ||
| sub(/\].*$/, "", heading) | ||
| if (found) exit | ||
| found = (heading == version) | ||
| } | ||
| found { print } | ||
| ' "$CHANGELOG" | ||
| 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| name: Lint PR | ||
|
|
||
| on: | ||
| pull_request: | ||
| branches: [main] | ||
| types: [opened, reopened, edited, synchronize] | ||
|
|
||
| permissions: | ||
| pull-requests: read | ||
|
|
||
| jobs: | ||
| check: | ||
| name: Validate PR title | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: amannn/action-semantic-pull-request@2252a14e810aa9b85c2d560bd7070c802206ecf6 # v6.1.2 | ||
| env: | ||
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
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,36 @@ | ||
| # Called by release.yaml after the release and its artifacts are ready. | ||
| name: Publish to BCR | ||
|
|
||
| on: | ||
| workflow_call: | ||
| inputs: | ||
| tag_name: | ||
| description: Validated unprefixed release tag | ||
| required: true | ||
| type: string | ||
| secrets: | ||
| publish_token: | ||
| description: Token for pushing to the BCR fork and opening its pull request | ||
| required: true | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| jobs: | ||
| publish: | ||
| permissions: | ||
| actions: read | ||
| contents: write | ||
| id-token: write | ||
| attestations: write | ||
| uses: bazel-contrib/publish-to-bcr/.github/workflows/publish.yaml@v1.7.0 # 1ae09341a6014e9bea052879c42392ac6b8b632c | ||
| with: | ||
| tag_name: ${{ inputs.tag_name }} | ||
| tag_prefix: '' | ||
| registry_fork: modular/bazel-central-registry | ||
| attest: true | ||
| draft: false | ||
| download_default_release_artifacts: true | ||
| release_artifacts_run_id: ${{ github.run_id }} | ||
| secrets: | ||
| publish_token: ${{ secrets.publish_token }} |
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,59 @@ | ||
| name: Release Please | ||
|
|
||
| on: | ||
| push: | ||
| branches: [main] | ||
| workflow_dispatch: | ||
|
|
||
| permissions: {} | ||
|
|
||
| # Separate from release.yaml's group because this workflow calls it. | ||
| concurrency: | ||
| group: release-please | ||
| cancel-in-progress: false | ||
|
|
||
| jobs: | ||
| release-please: | ||
| if: github.repository == 'modular/rules_mojo' && github.ref == 'refs/heads/main' | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| actions: write # Dispatch CI on the release PR branch. | ||
| contents: write | ||
| issues: write | ||
| pull-requests: write | ||
| outputs: | ||
| release_created: ${{ steps.release.outputs.release_created }} | ||
| tag_name: ${{ steps.release.outputs.tag_name }} | ||
| steps: | ||
| # GITHUB_TOKEN-created PRs and tags do not trigger other workflows. | ||
| - name: Update release PR and release merged PRs | ||
| id: release | ||
| uses: googleapis/release-please-action@45996ed1f6d02564a971a2fa1b5860e934307cf7 # v5.0.0 | ||
| with: | ||
| token: ${{ secrets.GITHUB_TOKEN }} | ||
| config-file: release-please-config.json | ||
| manifest-file: .release-please-manifest.json | ||
| - name: Run CI on the release PR | ||
| if: steps.release.outputs.pr != '' | ||
| env: | ||
| GH_TOKEN: ${{ github.token }} | ||
| GH_REPO: ${{ github.repository }} | ||
| RELEASE_PR: ${{ steps.release.outputs.pr }} | ||
| run: | | ||
| branch=$(jq -er '.headBranchName' <<< "$RELEASE_PR") | ||
| gh workflow run ci.yaml --ref "$branch" | ||
|
|
||
| release: | ||
| needs: release-please | ||
| # Still package a created release if a later release PR update or CI dispatch fails. | ||
| if: always() && needs.release-please.outputs.release_created == 'true' | ||
| uses: ./.github/workflows/release.yaml | ||
| with: | ||
| tag_name: ${{ needs.release-please.outputs.tag_name }} | ||
| secrets: | ||
| publish_token: ${{ secrets.BCR_PUBLISH_TOKEN }} | ||
| permissions: | ||
| actions: read | ||
| contents: write | ||
| id-token: write | ||
| attestations: write |
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,123 @@ | ||
| name: Release | ||
|
|
||
| on: | ||
| workflow_call: | ||
| inputs: | ||
| tag_name: | ||
| description: Existing unprefixed release tag (for example, 0.9.0) | ||
| required: true | ||
| type: string | ||
| secrets: | ||
| publish_token: | ||
| description: Token for pushing to the BCR fork and opening its pull request | ||
| required: true | ||
| BCR_PUBLISH_TOKEN: | ||
| description: Repository secret used as the fallback for manual dispatch | ||
| required: false | ||
| workflow_dispatch: | ||
| inputs: | ||
| tag_name: | ||
| description: Existing unprefixed release tag (for example, 0.9.0) | ||
| required: true | ||
| type: string | ||
| push: | ||
| tags: | ||
| - '[0-9]*.[0-9]*.[0-9]*' | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| # Serialize release runs to prevent competing preparations. | ||
| concurrency: | ||
| group: release | ||
| cancel-in-progress: false | ||
|
|
||
| jobs: | ||
| validate: | ||
| if: github.repository == 'modular/rules_mojo' && (github.ref == 'refs/heads/main' || (github.event_name == 'push' && startsWith(github.ref, 'refs/tags/'))) | ||
| runs-on: ubuntu-latest | ||
| outputs: | ||
| tag_name: ${{ steps.validate.outputs.tag_name }} | ||
| generate_release_notes: ${{ steps.validate.outputs.generate_release_notes }} | ||
| steps: | ||
| - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | ||
| with: | ||
| fetch-depth: 0 | ||
| persist-credentials: false | ||
| - name: Validate release tag | ||
| id: validate | ||
| env: | ||
| GH_TOKEN: ${{ github.token }} | ||
| RELEASE_TAG: ${{ inputs.tag_name || github.ref_name }} | ||
| shell: bash | ||
| run: | | ||
| set -euo pipefail | ||
| NUMBER='(0|[1-9][0-9]*)' | ||
| IDENTIFIER="($NUMBER|[0-9]*[A-Za-z-][0-9A-Za-z-]*)" | ||
| if [[ ! "$RELEASE_TAG" =~ ^$NUMBER\.$NUMBER\.$NUMBER(-$IDENTIFIER(\.$IDENTIFIER)*)?$ ]]; then | ||
| echo 'Expected an unprefixed version such as 0.9.0 or 0.9.0-rc.1' >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Require an existing upstream tag whose commit belongs to main. | ||
| git fetch --no-tags https://github.com/modular/rules_mojo.git \ | ||
| +refs/heads/main:refs/remotes/upstream/main \ | ||
| "+refs/tags/$RELEASE_TAG:refs/tags/$RELEASE_TAG" | ||
| COMMIT=$(git rev-parse --verify "refs/tags/$RELEASE_TAG^{commit}") | ||
| git merge-base --is-ancestor "$COMMIT" refs/remotes/upstream/main | ||
| for path in .github/workflows/{release.yaml,publish.yaml,release_prep.sh} \ | ||
| .bcr/{metadata.template.json,source.template.json,presubmit.yml}; do | ||
| git cat-file -e "$COMMIT:$path" | ||
| done | ||
|
|
||
| # Release Please creates the GitHub release before packaging. Allow | ||
| # updating it and retrying uploads, but never republish a BCR version. | ||
| PUBLISHED=$(gh api repos/bazelbuild/bazel-central-registry/contents/modules/rules_mojo/metadata.json \ | ||
| -H 'Accept: application/vnd.github.raw+json' \ | ||
| | jq --arg tag "$RELEASE_TAG" '.versions | index($tag) != null') | ||
| if [[ "$PUBLISHED" == true ]]; then | ||
| echo "rules_mojo@$RELEASE_TAG is already in the BCR" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| ENTRY='' | ||
| if git cat-file -e "$COMMIT:CHANGELOG.md" 2>/dev/null; then | ||
| git show "$COMMIT:CHANGELOG.md" > "$RUNNER_TEMP/release-changelog.md" | ||
| ENTRY=$(bash .github/workflows/changelog_entry.sh "$RELEASE_TAG" "$RUNNER_TEMP/release-changelog.md") | ||
| fi | ||
| if [[ -n "$ENTRY" ]]; then | ||
| echo 'generate_release_notes=false' >> "$GITHUB_OUTPUT" | ||
| else | ||
| echo 'generate_release_notes=true' >> "$GITHUB_OUTPUT" | ||
| fi | ||
| echo "tag_name=$RELEASE_TAG" >> "$GITHUB_OUTPUT" | ||
| echo "Validated $RELEASE_TAG at upstream main commit $COMMIT" | ||
|
|
||
| release: | ||
| needs: validate | ||
| permissions: | ||
| contents: write | ||
| id-token: write | ||
| attestations: write | ||
| uses: bazel-contrib/.github/.github/workflows/release_ruleset.yaml@v7.7.0 # 1d798ff015ed0696433e01e2c3ccbb2abefadad7 | ||
| with: | ||
| tag_name: ${{ needs.validate.outputs.tag_name }} | ||
| prerelease: false | ||
| draft: false | ||
| generate_release_notes: ${{ needs.validate.outputs.generate_release_notes == 'true' }} | ||
| # Cache writes are reserved for upstream main push CI runs. | ||
| mount_bazel_caches: false | ||
| release_files: rules_mojo-*.tar.gz | ||
|
|
||
| publish-to-bcr: | ||
| needs: [validate, release] | ||
| permissions: | ||
| actions: read | ||
| contents: write | ||
| id-token: write | ||
| attestations: write | ||
| uses: ./.github/workflows/publish.yaml | ||
| with: | ||
| tag_name: ${{ needs.validate.outputs.tag_name }} | ||
| secrets: | ||
| publish_token: ${{ secrets.publish_token || secrets.BCR_PUBLISH_TOKEN }} | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.