Skip to content

Commit

Permalink
Use pkg.pr.new for snapshots (#3269)
Browse files Browse the repository at this point in the history
  • Loading branch information
IMax153 authored Jul 16, 2024
1 parent b37a8c7 commit c527a03
Showing 1 changed file with 22 additions and 19 deletions.
41 changes: 22 additions & 19 deletions .github/workflows/snapshot.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
name: Snapshot

on:
issue_comment:
types: [created]
Expand All @@ -25,14 +26,14 @@ jobs:
env:
COMMENT: ${{ github.event.comment.body }}
run: |
if [[ $COMMENT =~ ^/snapshot([[:space:]]([a-z]{3,12}))?$ ]]; then
if [[ $COMMENT == "/snapshot" ]]; then
snapshot="${BASH_REMATCH[2]:-snapshot}"
echo "snapshot=$snapshot" >> $GITHUB_OUTPUT
else
exit 1
fi
- name: Initial comment
- name: Create initial comment
id: comment
uses: peter-evans/create-or-update-comment@v4
env:
Expand Down Expand Up @@ -63,41 +64,43 @@ jobs:
- name: Install dependencies
uses: ./.github/actions/setup

- name: Version snapshot
run: pnpm changeset version --snapshot ${{ steps.command.outputs.snapshot }} | grep -q "All files have been updated"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Build snapshot
- name: Build package
run: pnpm build

- name: Set registry config
run: pnpm config set --location project "//registry.npmjs.org/:_authToken" "${{ secrets.NPM_TOKEN }}"

- name: Publish snapshot
- name: Create snapshot
id: snapshot
run: |
# Publish and extract published tags from stdout.
output=$(pnpm changeset publish --tag ${{ steps.command.outputs.snapshot }} --no-git-tag)
output=$(echo "$output" | awk '/packages published successfully:/{flag=1; next} flag')
output=$(echo "$output" | grep -o '[^ ]*@[^ ]*' | awk '{print "\"" $0 "\""}' | paste -sd ',')
echo "tags=[$output]" >> $GITHUB_OUTPUT
snapshots=$(pnpx pkg-pr-new@0.0.17 publish --compact --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.tags }}.map(tag => '```sh\n' + `pnpm add ${tag}` + '\n```')
const commands = ${{ steps.snapshot.outputs.snapshots }}.map((snapshot) => {
const [package, installer] = snapshot.split(": ")
const [, sha] = installer.split("@")
const header = `<details><summary><b>${package} (${sha})</b></summary><p>`
const content = "\n```sh\n" + installer + "\n```\n"
const footer = `</p></details>`
return [header, content, footer].join("\n")
})
const header = `**Good news @${{ github.actor }}, your snapshot has been published!**`
const footer = `You can review the build log [here](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}).`
await github.rest.issues.updateComment({
comment_id: ${{ steps.comment.outputs.comment-id }},
owner: context.repo.owner,
repo: context.repo.repo,
body: `${header}\n\n${commands.join('\n')}\n\n${footer}`
body: `${header}\n\n${commands.join("\n")}\n\n${footer}`
})
- name: Update comment (failure)
Expand Down

0 comments on commit c527a03

Please sign in to comment.