diff --git a/.changeset/config.json b/.changeset/config.json index 55d4474a..a25c22c5 100644 --- a/.changeset/config.json +++ b/.changeset/config.json @@ -10,5 +10,6 @@ "updateInternalDependencies": "patch", "fixed": [], "linked": [], - "ignore": [] + "ignore": [], + "privatePackages": { "version": true, "tag": false } } diff --git a/.github/comment-on-release/README.md b/.github/comment-on-release/README.md index cff4576f..eebaf946 100644 --- a/.github/comment-on-release/README.md +++ b/.github/comment-on-release/README.md @@ -51,11 +51,13 @@ Add this step to your `.github/workflows/release.yml` file after the `changesets - name: Comment on PRs about release if: steps.changesets.outputs.published == 'true' - uses: TanStack/config/.github/comment-on-release@main + uses: TanStack/config/.github/comment-on-release@ # v1.0.0 with: published-packages: ${{ steps.changesets.outputs.published-packages }} ``` +Use the commit and version of the latest "Actions vX.Y.Z" [release](https://github.com/TanStack/config/releases). + ## Requirements - Must be using [Changesets](https://github.com/changesets/changesets) for releases diff --git a/.github/package.json b/.github/package.json new file mode 100644 index 00000000..6eec23bd --- /dev/null +++ b/.github/package.json @@ -0,0 +1,6 @@ +{ + "name": "@tanstack/config-actions", + "version": "1.0.0", + "private": true, + "description": "Version of the shared GitHub Actions in this directory." +} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 6a4709da..7edacdf3 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -50,3 +50,14 @@ jobs: uses: $/.github/comment-on-release with: published-packages: ${{ steps.changesets.outputs.published-packages }} + - name: Release Actions + if: github.ref == 'refs/heads/main' + env: + GH_TOKEN: ${{ github.token }} + run: | + # Release the commit on main that set the version. The checkout may + # hold a version that Changesets bumped for the version PR. + sha="$(git log -1 --format=%H "$GITHUB_SHA" -- .github/package.json)" + tag="v$(git show "$sha:.github/package.json" | jq -r .version)" + gh release view "$tag" > /dev/null 2>&1 || + gh release create "$tag" --target "$sha" --title "Actions $tag" --notes "Pin the actions as @$sha # $tag" --latest=false diff --git a/docs/ci-cd.md b/docs/ci-cd.md index 3f20b8ac..eb0c5249 100644 --- a/docs/ci-cd.md +++ b/docs/ci-cd.md @@ -13,6 +13,34 @@ title: CI/CD - Runs tests for code merged into release branches - Runs `nx run-many`, which executes all tasks and ensures the outputs are present (necessary for publishing builds) - Uses [Changesets](https://github.com/changesets/changesets) to handle versioning and publishing + - Creates a `vX.Y.Z` release for the shared actions when their version changes + +## Shared Actions + +Other TanStack repositories use three composite actions from this repository: + +- `.github/setup`: sets up Node and pnpm +- `.github/changeset-preview`: comments on a pull request with the versions Changesets would release +- `.github/comment-on-release`: comments on pull requests and linked issues once they are released + +The three actions share one version. Pin them to the commit of a release and put the release tag in the comment: + +```yaml +- name: Setup Tools + uses: TanStack/config/.github/setup@ # v1.0.0 +``` + +Each "Actions vX.Y.Z" [release](https://github.com/TanStack/config/releases) lists the commit to pin. Renovate updates the commit and the comment together when a new release exists. + +Do not put `# main` in the comment. zizmor checks that the ref in the comment still points at the pinned commit, and `main` moves with every package release. + +### Releasing the Actions + +Changesets versions the actions as the private package `@tanstack/config-actions` in `.github/package.json`. When you change an action, add a changeset for that package. After the "Version Packages" pull request is merged, `release.yml` creates the `vX.Y.Z` release for the new version. + +Changesets would tag the package as `@tanstack/config-actions@X.Y.Z`, and Renovate does not read that as a version. The workflow creates the plain `vX.Y.Z` tag for that reason. + +Release tags are immutable. Do not add a moving `v1` tag: a `# v1` comment would fail zizmor every time the tag moves. ## Nx diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml index 3a344f78..5ac87cef 100644 --- a/pnpm-workspace.yaml +++ b/pnpm-workspace.yaml @@ -3,6 +3,7 @@ linkWorkspacePackages: true preferWorkspacePackages: true packages: + - .github - integrations/* - packages/*