Skip to content

[cross-runtime] [Feature requests] Tauri support & more methods #196

[cross-runtime] [Feature requests] Tauri support & more methods

[cross-runtime] [Feature requests] Tauri support & more methods #196

Workflow file for this run

name: Snapit
on:
issue_comment:
types: [created]
jobs:
snapshot:
name: Snapshot release
if: |
github.event.issue.pull_request &&
github.event.comment.body == '/snapit'
runs-on: ubuntu-latest
steps:
- name: Add initial reaction
uses: peter-evans/create-or-update-comment@v2
with:
comment-id: ${{ github.event.comment.id }}
reactions: eyes
- name: Validate and get pull request data
uses: actions/github-script@v6
id: pr_data
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
script: |
try {
const pullRequest = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number,
})
// Pull request from fork
if (context.payload.repository.full_name !== pullRequest.data.head.repo.full_name) {
const errorMessage = '`/snapit` is not supported on pull requests from forked repositories.'
await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: errorMessage,
})
core.setFailed(errorMessage)
return
}
core.setOutput('repoFullName', pullRequest.data.head.repo.full_name)
core.setOutput('headSha', pullRequest.data.head.sha)
} catch (err) {
core.setFailed(`Request failed with error ${err}`)
}
# issue_comment requires us to checkout the branch
# https://github.com/actions/checkout/issues/331#issuecomment-707103442
- name: Checkout pull request branch
uses: actions/checkout@v2
with:
repository: ${{ steps.pr_data.outputs.repoFullName }}
ref: ${{ steps.pr_data.outputs.headSha }}
# Because changeset entries are consumed and removed on the
# 'changeset-release/main' branch, we need to reset the files
# so the following 'changeset version --snapshot' command will
# regenerate the package version bumps with the snapshot releases
- name: Reset changeset entries on changeset-release/main branch
run: |
if [[ $(git branch --show-current) == 'changeset-release/main' ]]; then
git checkout origin/main -- .changeset
fi
- name: Setup Node.js 16
uses: actions/setup-node@v3
with:
node-version: 16
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Create an .npmrc
run: |
cat << EOF > "$HOME/.npmrc"
//registry.npmjs.org/:_authToken=$NPM_TOKEN
EOF
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Create and publish snapshot release
uses: actions/github-script@v6
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
script: |
const execa = require('execa')
await execa.command('npm run version-packages -- --snapshot snapshot-release', { stdio: 'inherit' })
const releaseProcess = execa.command('npm run release -- --no-git-tags --snapshot --tag snapshot-release')
releaseProcess.stdout.pipe(process.stdout)
const {stdout} = await releaseProcess
const newTags = Array.from(
stdout.matchAll(/New tag:\s+([^\s\n]+)/g),
).map(
([_, tag]) => tag,
)
if (newTags.length) {
const multiple = newTags.length > 1
const body = (
`**Thanks @${context.actor}! ` +
`Your snapshot${multiple ? 's have' : ' has'} been shipped. 🚢**\n\n` +
`Test the snapshot${multiple ? 's' : ''} by updating your \`package.json\` ` +
`with the newly published version${multiple ? 's' : ''}:\n` +
newTags.map(tag => (
'```sh\n' +
`npm i ${tag}\n` +
'```'
)).join('\n')
)
await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body,
})
return true
}
return false
- name: Add final reaction
uses: peter-evans/create-or-update-comment@v2
with:
comment-id: ${{ github.event.comment.id }}
reactions: rocket