Skip to content
Merged
Show file tree
Hide file tree
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
103 changes: 103 additions & 0 deletions .github/workflows/release-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
name: Release PR

on:
issue_comment:
types: [created]

jobs:
release_check:
if: github.repository == 'changesets/action' && github.event.issue.pull_request && startsWith(github.event.comment.body, '/release-pr')
runs-on: ubuntu-latest
steps:
- id: report_in_progress
run: |
echo "in_progress_reaction_id=$(gh api /repos/${{github.repository}}/issues/comments/${{github.event.comment.id}}/reactions -f content='eyes' --jq '.id')" >> "$GITHUB_OUTPUT"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- id: check_authorization
run: |
if [[ $AUTHOR_ASSOCIATION == 'MEMBER' || $AUTHOR_ASSOCIATION == 'OWNER' || $AUTHOR_ASSOCIATION == 'COLLABORATOR' ]]
then
echo "User is authorized to release"
else
echo "User is not authorized to release"
exit 1
fi
env:
AUTHOR_ASSOCIATION: ${{ github.event.comment.author_association }}

outputs:
in_progress_reaction_id: ${{ steps.report_in_progress.outputs.in_progress_reaction_id }}

release:
if: github.repository == 'changesets/action'
timeout-minutes: 20
runs-on: ubuntu-latest
needs: release_check
steps:
- uses: actions/checkout@v4

- name: Checkout pull request
run: gh pr checkout ${{ github.event.issue.number }}
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Check if Version Packages PR
id: check_version_packages
run: |
echo "version_packages=$(gh pr view ${{ github.event.issue.number }} --json headRefName --jq '.headRefName|startswith("changeset-release/")')" >> "$GITHUB_OUTPUT"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Reset Version Packages PR
if: steps.check_version_packages.outputs.version_packages == 'true'
run: git reset --hard HEAD~1

- uses: actions/setup-node@v4
with:
node-version: "18"
cache: "yarn"

- name: Install Dependencies
run: yarn --frozen-lockfile

- run: yarn changeset version --snapshot pr${{ github.event.issue.number }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Build
run: yarn build

- name: Release snapshot version
run: yarn run release:pr

- run: gh api /repos/${{ github.repository }}/issues/comments/${{ github.event.comment.id }}/reactions -f content='rocket'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- run: gh api -X DELETE /repos/${{ github.repository }}/issues/comments/${{ github.event.comment.id }}/reactions/${{ needs.release_check.outputs.in_progress_reaction_id }}
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- run: gh pr comment ${{ github.event.issue.number }} --body "The [${{ github.repository }}@$(git rev-parse HEAD)](https://github.com/${{ github.repository }}/commit/$(git rev-parse HEAD)) release triggered by [this comment](${{ github.event.comment.url }}) has [succeeded](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})."
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

report-failure-if-needed:
needs: [release_check, release]
timeout-minutes: 2
runs-on: ubuntu-latest
if: failure() && github.repository == 'changesets/action' && (needs.release_check.result == 'failure' || needs.release.result == 'failure')
steps:
- run: gh api /repos/${{ github.repository }}/issues/comments/${{ github.event.comment.id }}/reactions -f content='-1'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- run: gh api -X DELETE /repos/${{ github.repository }}/issues/comments/${{ github.event.comment.id }}/reactions/${{ needs.release_check.outputs.in_progress_reaction_id }}
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- run: gh pr comment ${{ github.event.issue.number }} --body "The release triggered by [this comment](${{ github.event.comment.url }}) has [failed](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})."
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
"typecheck": "tsc",
"changeset": "changeset",
"bump": "node ./scripts/bump.js",
"release": "node ./scripts/release.js"
"release": "node ./scripts/release.js",
"release:pr": "node ./scripts/release-pr.js"
},
"engines": {
"node": ">= 20"
Expand Down
21 changes: 21 additions & 0 deletions scripts/release-pr.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const path = require("path");
const { exec, getExecOutput } = require("@actions/exec");

const { version } = require("../package.json");
const tag = `v${version}`;
const releaseLine = "pr-release";

process.chdir(path.join(__dirname, ".."));

(async () => {
await exec("git", ["checkout", "--detach"]);
await exec("git", ["add", "--force", "dist"]);
await exec("git", ["commit", "-m", tag]);

await exec("git", [
"push",
"--force",
"origin",
`HEAD:refs/heads/${releaseLine}`,
]);
})();