From 48188cecf30be040e0566a63eba8ef35e2fe1c63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ari=20Perkki=C3=B6?= Date: Mon, 25 Nov 2024 10:13:26 +0200 Subject: [PATCH] ci: preview releases by PR tags --- .github/workflows/publish-commit.yaml | 53 +++++---------------------- 1 file changed, 9 insertions(+), 44 deletions(-) diff --git a/.github/workflows/publish-commit.yaml b/.github/workflows/publish-commit.yaml index 316cdf87..ad3a79b0 100644 --- a/.github/workflows/publish-commit.yaml +++ b/.github/workflows/publish-commit.yaml @@ -1,55 +1,20 @@ -# PRs can be published by commenting `/pkg-pr-new` in the PR +# PRs can be published by adding `pkg-pr-new` tag -name: Publish Any Commit +name: PR Preview Releases on: - issue_comment: - types: [created] + push: + branches: [main] + pull_request: + types: [opened, synchronize, labeled] jobs: - build: - if: github.repository == 'stackblitz/tutorialkit' && (github.event_name == 'push' || github.event.issue.pull_request && startsWith(github.event.comment.body, '/pkg-pr-new')) + release: + if: github.repository == 'stackblitz/tutorialkit' && (github.ref == 'refs/heads/main' || contains(github.event.pull_request.labels.*.name, 'pkg-pr-new')) runs-on: ubuntu-latest + name: 'Release: pkg.pr.new' 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: