Fix the snapshot action #2729
Workflow file for this run
This file contains 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
name: Snapshot | |
on: | |
pull_request: | |
branches: [main, next-minor, next-major] | |
push: | |
branches: [main, next-minor, next-major] | |
jobs: | |
snapshot: | |
name: Snapshot | |
if: ${{ github.repository_owner == 'Effect-Ts' }} | |
runs-on: ubuntu-latest | |
timeout-minutes: 10 | |
permissions: | |
id-token: write | |
pull-requests: write | |
steps: | |
- name: Enforce permission requirement | |
uses: prince-chrismc/check-actor-permissions-action@v3 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
permission: write | |
- name: Dump GitHub context | |
env: | |
GITHUB_CONTEXT: ${{ toJson(github) }} | |
run: echo "$GITHUB_CONTEXT" | |
- name: Initial comment | |
id: comment | |
uses: peter-evans/create-or-update-comment@v4 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
issue-number: ${{ github.event.issue.number }} | |
body: | | |
**Alright @${{ github.actor }}, I'm working on the snapshot!** | |
You can follow the progress [here](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}). | |
- name: Checkout default branch | |
uses: actions/checkout@v4 | |
- name: Checkout pull request branch | |
run: gh pr checkout ${{ github.event.issue.number }} | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Get current branch name | |
id: branch | |
run: echo "branch=$(git branch --show-current)" >> $GITHUB_OUTPUT | |
- name: Checkout main branch for changeset release | |
if: ${{ steps.branch.outputs.branch == 'changeset-release/main' }} | |
run: git checkout origin/main | |
- name: Install dependencies | |
uses: ./.github/actions/setup | |
- name: Build package | |
run: pnpm build | |
- name: Create snapshot | |
id: snapshot | |
run: | | |
snapshots=$(pnpx pkg-pr-new@0.0.17 publish --pnpm --comment=off ./packages/*) | |
echo "${snapshots}" | |
snapshots=$(echo "${snapshots}" | awk ' | |
/⚡️ Your npm packages are published./ \ | |
{ found=1; next } found \ | |
{ sub(/npm i/, "pnpm add"); print "\"" $0 "\"" } | |
' | paste -sd ',') | |
echo "snapshots=[$snapshots]" >> $GITHUB_OUTPUT | |
- name: Update comment (success) | |
uses: actions/github-script@v7 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
script: | | |
const commands = ${{ steps.snapshot.outputs.snapshots }}.map((snapshot) => { | |
const [package, installer] = snapshot.split(": ") | |
const header = `<b>${package}:</b><br />` | |
const content = "\n```sh\n" + installer + "\n```\n" | |
return [header, content].join("\n") | |
}) | |
const header = `**Good news @${{ github.actor }}, your snapshot has been published!**\n\n` | |
+ `You can review the build log [here](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}).` | |
+ "\n" | |
+ "Commit: ${{ github.event.head.sha }}" | |
const packages = `<details><summary><b>Packages:</b></summary>\n\n${commands.join("\n")}\n\n</details>` | |
await github.rest.issues.updateComment({ | |
comment_id: ${{ steps.comment.outputs.comment-id }}, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
body: `${header}\n\n${packages}` | |
}) | |
- name: Update comment (failure) | |
if: failure() | |
uses: peter-evans/create-or-update-comment@v4 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
comment-id: ${{ steps.comment.outputs.comment-id }} | |
edit-mode: replace | |
body: | | |
**Sorry @${{ github.actor }}, I failed to publish the snapshot!** | |
You can review the build log [here](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}). |