Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 74 additions & 10 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ jobs:
outputs:
hasChangesets: ${{ steps.changesets.outputs.has-changesets }}
releaseExists: ${{ steps.published.outputs.exists }}
title: ${{ steps.version.outputs.title }}
permissions:
contents: write
pull-requests: write
contents: read
steps:
- name: Checkout repo
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: true
persist-credentials: false

- name: Setup Node
uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
Expand All @@ -47,15 +47,29 @@ jobs:
fi
echo "title=${title}" >> "$GITHUB_OUTPUT"

- name: Update release PR
- name: Check for changesets
id: changesets
uses: changesets/action@ae32849d5ba541f9ae29e40e22a623bc13562f51 # v2.1.2
run: |
if find .changeset -maxdepth 1 -name "*.md" ! -name README.md | grep -q .; then
echo "has-changesets=true" >> "$GITHUB_OUTPUT"
else
echo "has-changesets=false" >> "$GITHUB_OUTPUT"
fi

- name: Version packages
if: steps.changesets.outputs.has-changesets == 'true'
run: |
npm run version
git add --all
git diff --cached --binary "$GITHUB_SHA" > "$RUNNER_TEMP/version.patch"

- name: Upload the version changes
if: steps.changesets.outputs.has-changesets == 'true'
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
commit-message: ${{ steps.version.outputs.title }}
github-token: ${{ secrets.GITHUB_TOKEN }}
pr-draft: create
pr-title: ${{ steps.version.outputs.title }}
version-script: npm run version
if-no-files-found: error
name: version
path: ${{ runner.temp }}/version.patch

- name: Check if publish is needed
id: published
Expand All @@ -70,6 +84,56 @@ jobs:
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

release-pr:
name: Release PR
if: github.ref == 'refs/heads/main' && needs.changelog.outputs.hasChangesets == 'true'
runs-on: ubuntu-latest
needs: changelog
environment: release-pr
permissions:
contents: read
steps:
- name: Gather credentials
id: credentials
uses: actions/create-github-app-token@f418cff399f7aef4c2f0ad47e25ca7a6abbdd6fc # v3.4.0
with:
client-id: ${{ secrets.GH_APP_CLIENT_ID }}
private-key: ${{ secrets.GH_APP_PRIVATE_KEY }}
owner: ${{ github.repository_owner }}
repositories: ${{ github.event.repository.name }}
permission-contents: write
permission-pull-requests: write

- name: Checkout repo
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false

- name: Download the version changes
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
name: version
path: ${{ runner.temp }}/version

- name: Check the version changes
run: |
index="${RUNNER_TEMP}/version.index"
GIT_INDEX_FILE="$index" git read-tree HEAD
GIT_INDEX_FILE="$index" git apply --cached "${RUNNER_TEMP}/version/version.patch"
if GIT_INDEX_FILE="$index" git ls-files --stage | grep -v -E '^100(644|755) '; then
echo "::error::The version changes hold a file that isn't a regular file"
exit 1
fi

- name: Update release PR
uses: changesets/action@ae32849d5ba541f9ae29e40e22a623bc13562f51 # v2.1.2
with:
commit-message: ${{ needs.changelog.outputs.title }}
github-token: ${{ steps.credentials.outputs.token }}
pr-draft: create
pr-title: ${{ needs.changelog.outputs.title }}
version-script: git apply ${{ runner.temp }}/version/version.patch

build:
name: Build
if: github.ref == 'refs/heads/main' && needs.changelog.outputs.hasChangesets == 'false' && needs.changelog.outputs.releaseExists == 'false'
Expand Down
Loading