radix-vue / radix-vue

Vue port of Radix UI Primitives. An open-source UI component library for building high-quality, accessible design systems and web apps.
https://radix-vue.com
MIT License
2.77k stars 149 forks source link

ci: add pkg.pr.new GitHub action workflow #931

Closed sadeghbarati closed 2 weeks ago

sadeghbarati commented 2 weeks ago

You need to configure pkg.pr.new GitHub app first

https://github.com/stackblitz-labs/pkg.pr.new

I need some help here cause I have zero experience in advanced GitHub actions

based on workflow file I want to run pkg.pr.new action on

One more thing about packages/plugins, how to check this path if it's changed then run build all packages

in another word, if the user push 100 commits workflow doesn't run

until someone approved the PR after that any other (push, synchronize, reopened) allowed to trigger the workflow job

sadeghbarati commented 2 weeks ago

@zernonia why not update to latest pnpm?

GitHub workflow files are outdated one uses node 16 one uses 18 😕

sadeghbarati commented 2 weeks ago
Chat GPT4o response xd

To configure GitHub Actions to run on `push`, `pull_request`, and `pull_request_review` events with the condition that it only runs if the pull request is approved, you need to use the GitHub Actions `workflow_run` event to create a workflow that is triggered after the approval. Here is how you can set it up: 1. **Create the main workflow**: This workflow will run on `push`, `pull_request`, and `pull_request_review` events but will be conditional on the pull request being approved. 2. **Create a second workflow**: This workflow will be triggered by the `workflow_run` event when the main workflow is completed. ### Step 1: Main Workflow Create a workflow file `.github/workflows/main.yml`: ```yaml name: Main Workflow on: push: pull_request: pull_request_review: types: [submitted] jobs: check-approval: runs-on: ubuntu-latest steps: - name: Check if PR is approved id: check_pr_approved uses: actions/github-script@v6 with: script: | const { data: reviews } = await github.pulls.listReviews({ owner: context.repo.owner, repo: context.repo.repo, pull_number: context.payload.pull_request.number, }); const approved = reviews.some(review => review.state === 'approved'); core.setOutput('approved', approved); trigger-secondary-workflow: needs: check-approval if: steps.check_pr_approved.outputs.approved == 'true' runs-on: ubuntu-latest steps: - name: Trigger secondary workflow uses: benc-uk/workflow-dispatch@v1 with: workflow: 'Secondary Workflow' token: ${{ secrets.GITHUB_TOKEN }} ref: ${{ github.ref }} ``` ### Step 2: Secondary Workflow Create another workflow file `.github/workflows/secondary.yml`: ```yaml name: Secondary Workflow on: workflow_run: workflows: ["Main Workflow"] types: - completed jobs: run-actions: runs-on: ubuntu-latest steps: - name: Checkout repository uses: actions/checkout@v2 - name: Run your actions run: | echo "Running actions on approved PR" # Add your actual actions/commands here ``` ### Explanation - **Main Workflow**: - Listens to `push`, `pull_request`, and `pull_request_review` events. - The `check-approval` job checks if the pull request is approved by listing all reviews and looking for at least one with the state `approved`. - If the pull request is approved, the `trigger-secondary-workflow` job triggers the secondary workflow using `workflow-dispatch`. - **Secondary Workflow**: - Listens to the `workflow_run` event for the completion of the "Main Workflow". - Runs the necessary actions if the PR is approved. By structuring the workflows this way, you ensure that actions are only run if the pull request is approved, meeting your specified conditions.

sadeghbarati commented 2 weeks ago

cc @Aslemammad 🙏

Thanks for this tool this will help maintainers ❤️

Aslemammad commented 2 weeks ago

Thank you team for using https://pkg.pr.new! It means a lot to us.

zernonia commented 2 weeks ago

@zernonia why not update to latest pnpm?

GitHub workflow files are outdated one uses node 16 one uses 18 😕

Hahahaha no reason. Just didnt have the need to update because the pipeline we have is working now. If this new addition requires higher version of node, sure let's upgrade it!

zernonia commented 2 weeks ago

@sadeghbarati It's being triggered here

image

Seems like the publishing work. However it would be nice to have the App to comment the npm command. cc @Aslemammad

npm i https://pkg.pr.new/radix-vue/radix-vue@2de584a    
sadeghbarati commented 2 weeks ago

pkg.pr.new GitHub app configured after PR opened will close this and open same changes in new PR