From 3e08634b8bbbc65ca71a96ca514a8cce8e14faf6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ari=20Perkki=C3=B6?= Date: Wed, 21 Aug 2024 16:40:52 +0300 Subject: [PATCH] ci: setup pkg.pr.new --- .github/workflows/publish-commit.yaml | 71 +++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 .github/workflows/publish-commit.yaml diff --git a/.github/workflows/publish-commit.yaml b/.github/workflows/publish-commit.yaml new file mode 100644 index 00000000..8abe3fd8 --- /dev/null +++ b/.github/workflows/publish-commit.yaml @@ -0,0 +1,71 @@ +# Publishes main-branch's commits to pkg.pr.new +# PRs can be published by commenting `/pkg-pr-new` in the PR + +name: Publish Any Commit + +on: + push: + branches: + - main + issue_comment: + types: [created] + +jobs: + build: + if: github.repository == 'stackblitz/tutorialkit' && (github.event_name == 'push' || github.event.issue.pull_request && startsWith(github.event.comment.body, '/pkg-pr-new')) + runs-on: ubuntu-latest + + steps: + - if: github.event.issue.pull_request + uses: actions/github-script@v7 + with: + script: | + const user = context.payload.sender.login + console.log(`Validate user: ${user}`) + + let hasTriagePermission = false + try { + const { data } = await github.rest.repos.getCollaboratorPermissionLevel({ + owner: context.repo.owner, + repo: context.repo.repo, + username: user, + }); + hasTriagePermission = data.user.permissions.triage + } catch (e) { + console.warn(e) + } + + if (hasTriagePermission) { + console.log('Allowed') + await github.rest.reactions.createForIssueComment({ + owner: context.repo.owner, + repo: context.repo.repo, + comment_id: context.payload.comment.id, + content: '+1', + }) + } else { + console.log('Not allowed') + await github.rest.reactions.createForIssueComment({ + owner: context.repo.owner, + repo: context.repo.repo, + comment_id: context.payload.comment.id, + content: '-1', + }) + throw new Error('not allowed') + } + + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - uses: ./.github/actions/setup-and-build + + - name: Publish to pkg.pr.new + run: > + pnpm dlx pkg-pr-new@0.0 publish --compact --pnpm + ./packages/astro + ./packages/components/react + ./packages/runtime + ./packages/theme + ./packages/types