Skip to content

Commit

Permalink
Add github workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
HugoRCD committed Sep 3, 2024
1 parent 40b3004 commit 5408529
Show file tree
Hide file tree
Showing 3 changed files with 156 additions and 0 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Check if packages can be built

on:
pull_request:
branches:
- '**'

permissions:
contents: read

jobs:
autofix:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: oven-sh/setup-bun@v2

- name: 📦 Install dependencies
run: bun install

- name: 🛠️ Build
run: bun run build
70 changes: 70 additions & 0 deletions .github/workflows/label-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
name: Label PR

on:
pull_request_target:
types:
- opened
branches:
- main

jobs:
add-pr-labels:
name: Add PR labels
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
env:
PULL_REQUEST_TITLE: ${{ github.event.pull_request.title }}
with:
script: |
const labelsToAdd = []
const pullRequest = {
number: ${{ github.event.pull_request.number }},
title: process.env.PULL_REQUEST_TITLE,
labelsNames: ${{ toJson(github.event.pull_request.labels.*.name) }}
}
// Select label based on the type in PR title
const pullRequestTypeToLabelName = {
breaking: 'breaking',
feat: 'feature',
fix: 'bug',
build: 'build',
ci: 'ci',
docs: 'documentation',
enhancement: 'enhancement',
chore: 'dependencies',
perf: 'performance',
style: 'style',
test: 'test',
refactor: 'refactor',
revert: 'revert'
}
for (const [pullRequestType, labelName] of Object.entries(
pullRequestTypeToLabelName
)) {
if (
pullRequest.title.startsWith(pullRequestType) &&
!pullRequest.labelsNames.includes(
pullRequestTypeToLabelName[pullRequestType]
)
) {
labelsToAdd.push(labelName)
break
}
}
// Add selected labels
if (labelsToAdd.length > 0) {
github.rest.issues.addLabels({
issue_number: pullRequest.number,
owner: context.repo.owner,
repo: context.repo.repo,
labels: labelsToAdd
})
}
64 changes: 64 additions & 0 deletions .github/workflows/semantic-pull-request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: validate pr title

on:
pull_request_target:
types:
- opened
- reopened
- edited
- synchronize

permissions:
pull-requests: write

jobs:
validate-pr:
name: Validate PR title
if: ${{ !contains(github.actor, 'renovate') }}

runs-on: ubuntu-latest
steps:
- uses: amannn/action-semantic-pull-request@v5
id: lint_pr_title
with:
types: |
breaking
feat
fix
build
ci
docs
enhancement
chore
performance
style
test
refactor
revert
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- uses: marocchino/sticky-pull-request-comment@v2
# When the previous steps fail, the workflow would stop. By adding this
# condition you can continue the execution with the populated error message.
if: always() && (steps.lint_pr_title.outputs.error_message != null)
with:
header: pr-title-lint-error
message: |
Hey there and thank you for opening this pull request! 👋🏼
We require pull request titles to follow the [Conventional Commits specification](https://www.conventionalcommits.org/en/v1.0.0/) and it looks like your proposed title needs to be adjusted.
Details:
```
${{ steps.lint_pr_title.outputs.error_message }}
```
# Delete a previous comment when the issue has been resolved
- if: ${{ steps.lint_pr_title.outputs.error_message == null }}
uses: marocchino/sticky-pull-request-comment@v2
with:
header: pr-title-lint-error
message: |
Thank you for following the naming conventions! 🙏

0 comments on commit 5408529

Please sign in to comment.