diff --git a/.bcr/metadata.template.json b/.bcr/metadata.template.json new file mode 100644 index 0000000..84ca8e7 --- /dev/null +++ b/.bcr/metadata.template.json @@ -0,0 +1,17 @@ +{ + "homepage": "https://github.com/bmw-software-engineering/trlc", + "maintainers": [ + { + "email": "ambujsingh7566180876@gmail.com", + "github": "AAmbuj", + "name": "Ambuj Singh Kushwaha", + "github_user_id": 73685939 + } + ], + "repository": [ + "github:bmw-software-engineering/trlc" + ], + "versions": [], + "yanked_versions": {} +} + diff --git a/.bcr/presubmit.yml b/.bcr/presubmit.yml new file mode 100644 index 0000000..92ba9bb --- /dev/null +++ b/.bcr/presubmit.yml @@ -0,0 +1,18 @@ +matrix: + platform: + - debian12 + - ubuntu2204 + - macos + - windows + bazel: + - 7.x + - 8.x +tasks: + verify_api_examples: + name: "Verify api-examples" + platform: ${{ platform }} + bazel: ${{ bazel }} + build_targets: + - "@trlc//api-examples/..." + test_targets: + - "@trlc//api-examples/..." diff --git a/.bcr/source.template.json b/.bcr/source.template.json new file mode 100644 index 0000000..0f03e7a --- /dev/null +++ b/.bcr/source.template.json @@ -0,0 +1,5 @@ +{ + "integrity": "**leave this alone**", + "strip_prefix": "{REPO}-{VERSION}", + "url": "https://github.com/{OWNER}/{REPO}/releases/download/{TAG}/{TAG}.tar.gz" +} diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..b6420ef --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,46 @@ +name: Publish to BCR + +on: + workflow_call: + inputs: + tag_name: + required: true + type: string + registry_fork: + required: false + type: string + default: AAmbuj/bazel-central-registry + secrets: + BCR_PUBLISH_TOKEN: + required: true + workflow_dispatch: + inputs: + tag_name: + description: Git tag being released + required: true + type: string + registry_fork: + description: GitHub fork used to open the BCR PR (owner/repo) + required: false + type: string + default: AAmbuj/bazel-central-registry + +jobs: + publish: + uses: bazel-contrib/publish-to-bcr/.github/workflows/publish.yaml@v1.2.0 + with: + tag_name: ${{ inputs.tag_name }} + registry_fork: ${{ inputs.registry_fork }} + draft: true + attest: true + tag_prefix: "trlc-" + author_name: Ambuj Singh Kushwaha + author_email: ambujsingh7566180876@gmail.com + committer_name: github-actions[bot] + committer_email: 41898282+github-actions[bot]@users.noreply.github.com + permissions: + contents: write + id-token: write + attestations: write + secrets: + publish_token: ${{ secrets.BCR_PUBLISH_TOKEN }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..34c6f92 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,57 @@ +name: Release + +on: + workflow_dispatch: + inputs: + tag_name: + description: Git tag being released + required: true + type: string + registry_fork: + description: GitHub fork used to open the BCR PR (owner/repo) + required: false + type: string + default: AAmbuj/bazel-central-registry + push: + tags: + - "trlc-*" + +permissions: + id-token: write + attestations: write + contents: write + +jobs: + release: + uses: bazel-contrib/.github/.github/workflows/release_ruleset.yaml@v7.4.0 + with: + release_files: archives/*.* + prerelease: false + draft: true + tag_name: ${{ inputs.tag_name || github.ref_name }} + permissions: + id-token: write + attestations: write + contents: write + secrets: {} + + publish: + needs: release + uses: ./.github/workflows/publish.yml + with: + tag_name: ${{ inputs.tag_name || github.ref_name }} + registry_fork: ${{ inputs.registry_fork || 'AAmbuj/bazel-central-registry' }} + secrets: + BCR_PUBLISH_TOKEN: ${{ secrets.BCR_PUBLISH_TOKEN }} + + finalize: + needs: publish + runs-on: ubuntu-24.04 + permissions: + contents: write + steps: + - name: Publish draft release + run: gh release edit "$TAG" --draft=false --repo "$GITHUB_REPOSITORY" + env: + TAG: ${{ inputs.tag_name || github.ref_name }} + GH_TOKEN: ${{ github.token }} diff --git a/.github/workflows/release_prep.sh b/.github/workflows/release_prep.sh new file mode 100755 index 0000000..ec3238e --- /dev/null +++ b/.github/workflows/release_prep.sh @@ -0,0 +1,44 @@ +#!/usr/bin/env bash + +set -o errexit -o nounset -o pipefail + +TAG="$1" +# Tags use the format "trlc-X.Y.Z"; strip the prefix to get the bare version +# matching the tag_prefix configured in publish.yml +if [[ "$TAG" == trlc-* ]]; then + VERSION="${TAG#trlc-}" +else + echo "ERROR: tag '${TAG}' does not match expected format 'trlc-X.Y.Z'" >&2 + exit 1 +fi + +mkdir -p archives + +PREFIX="trlc-${VERSION}" +ARCHIVE="archives/${TAG}.tar.gz" + +git archive --format=tar --prefix="${PREFIX}/" "$TAG" | gzip > "$ARCHIVE" + +SHA=$(sha256sum "$ARCHIVE" | awk '{print $1}') + +cat << EOF +## Bzlmod + +Add this to your MODULE.bazel: + +\`\`\`starlark +bazel_dep(name = "trlc", version = "${VERSION}") +\`\`\` + +## WORKSPACE + +\`\`\`starlark +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") +http_archive( + name = "trlc", + sha256 = "${SHA}", + strip_prefix = "${PREFIX}", + url = "https://github.com/bmw-software-engineering/trlc/releases/download/${TAG}/${TAG}.tar.gz", +) +\`\`\` +EOF diff --git a/README.md b/README.md index 97f1dbe..ccf766e 100644 --- a/README.md +++ b/README.md @@ -72,3 +72,16 @@ Optional dependency (not installed automatically): * [Binary CVC5](https://github.com/cvc5/cvc5/releases/tag/cvc5-1.3.2) (An alternative to PyPI CVC5, make sure to rename the binary to `cvc5` and put it on your PATH). + +## Automated Release Flow + +Releases are automated through GitHub Actions: + +* Push a release tag using the format `trlc-X.Y.Z`. +* Workflow `.github/workflows/release.yml` creates a draft GitHub release and uploads `trlc-{TAG}.tar.gz`. +* Workflow `.github/workflows/publish.yml` opens a Bazel Central Registry PR through `publish-to-bcr`. +* After BCR publish succeeds, the release is finalized (published), which triggers `.github/workflows/package.yml` to publish wheels to PyPI. + +Required repository secret: + +* `BCR_PUBLISH_TOKEN`: Classic PAT with `workflow` and `repo` scopes, with access to your BCR fork (default fork: `AAmbuj/bazel-central-registry`). diff --git a/documentation/TUTORIAL.md b/documentation/TUTORIAL.md index 1ca5be3..b1e84ae 100644 --- a/documentation/TUTORIAL.md +++ b/documentation/TUTORIAL.md @@ -25,4 +25,5 @@ * [Advaned tips & tricks](TUTORIAL-ADVANCED-TYPES.md): some more advanced tips and tricks for large organisations * [Python API](TUTORIAL-API.md): writing a custom check with the API +* [Bazel Integration](TUTORIAL-BAZEL.md): using TRLC with Bazel * [CI Integration](TUTORIAL-CI.md): tips on how to integrate in your CI