Skip to content

Commit

Permalink
ci: 🎡 pull checker
Browse files Browse the repository at this point in the history
  • Loading branch information
suemor233 committed Jan 15, 2023
1 parent be5496c commit 8b7bca3
Show file tree
Hide file tree
Showing 2 changed files with 122 additions and 0 deletions.
File renamed without changes.
122 changes: 122 additions & 0 deletions .github/workflows/pull.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
name: Pull Request Checker

on:
pull_request:

jobs:
build:

strategy:
matrix:
node-version: [16.x, 18.x]
os: [ubuntu-latest, macos-latest]

runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- name: Cache pnpm modules
uses: actions/cache@v3
env:
cache-name: cache-pnpm-modules
with:
path: ~/.pnpm-store
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ matrix.node-version }}-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-${{ matrix.node-version }}-
- uses: pnpm/[email protected]
with:
version: latest
run_install: true
- name: Install dependencies
run: pnpm i --no-optional
- name: Build project
run: |
npm run build
test:
needs: build
strategy:
matrix:
node-version: [16.x, 18.x]
os: ['ubuntu-latest']

runs-on: ${{ matrix.os }}

steps:
- name: Add ci-passed label
if: ${{ success() && github.event.pull_request.draft == false }}
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
github.rest.issues.addLabels({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
labels: ['ci-passed']
})
- name: Remove ci-failed label
if: ${{ success() && github.event.pull_request.draft == false }}
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const labels = await github.rest.issues.listLabelsOnIssue({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo
})
const label = labels.data.find(label => label.name === 'ci-failed')
if (label) {
github.rest.issues.removeLabel({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
name: label.name
})
}
- name: Add ci-failed label
if: ${{ failure() && github.event.pull_request.draft == false }}
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const labels = await github.rest.issues.listLabelsOnIssue({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo
})
const label = labels.data.find(label => label.name === 'ci-failed')
if (!label) {
github.rest.issues.addLabels({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
labels: ['ci-failed']
})
}
- name: Remove ci-passed label
if: ${{ failure() && github.event.pull_request.draft == false }}
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const labels = await github.rest.issues.listLabelsOnIssue({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo
})
const hasPassedLabel = labels.data.some(label => label.name === 'ci-passed')
if (hasPassedLabel) {
github.rest.issues.removeLabel({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
name: 'ci-passed'
})
}

0 comments on commit 8b7bca3

Please sign in to comment.