Skip to content

Commit

Permalink
ci: fix misc (#51)
Browse files Browse the repository at this point in the history
  • Loading branch information
ginokent authored Jun 4, 2024
2 parents 0b5e32c + 067871d commit 0329cf9
Show file tree
Hide file tree
Showing 7 changed files with 191 additions and 33 deletions.
2 changes: 2 additions & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# ref: https://docs.github.com/ja/github/creating-cloning-and-archiving-repositories/creating-a-repository-on-github/about-code-owners
* @kunitsucom/owners
6 changes: 3 additions & 3 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: 2
updates:

- package-ecosystem: "github-actions" # See documentation for possible values
- package-ecosystem: "github-actions"
directory: "/" # Location of package manifests
schedule:
interval: "weekly"
Expand Down Expand Up @@ -46,7 +46,7 @@ updates:
- "*"

- package-ecosystem: "gomod"
directory: "/implementations/zerolog/" # Location of package manifests
directory: "/implementations/zap/" # Location of package manifests
schedule:
interval: "weekly"
day: "monday"
Expand All @@ -68,7 +68,7 @@ updates:
- "*"

- package-ecosystem: "gomod"
directory: "/implementations/zap/" # Location of package manifests
directory: "/implementations/zerolog/" # Location of package manifests
schedule:
interval: "weekly"
day: "monday"
Expand Down
29 changes: 29 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<!-- markdownlint-disable MD004 MD041 -->

## Ticket / Issue Number

> **Note**
> *Please fill in the ticket or issue number.*
> > Example:
> >
> > #3
## What's changed

> **Note**
> *Please explain what changes this pull request will make.*
> > Example:
> >
> > * Added functionality to perform 'bar' on 'foo'.
## Check List

- [ ] Assign labels
- [ ] Add appropriate test cases

## Remark

> **Note**
> *Please provide additional remarks if necessary.*
<!-- markdownlint-enable MD004 MD041 -->
40 changes: 25 additions & 15 deletions .github/workflows/go-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,10 @@ on:
push:
branches:
- main
paths-ignore:
- '.github/dependabot.yml'
- '.github/pull_request_template.md'
- '.github/release.yml'
- 'README.md'
# NO paths-ignore
pull_request:
# branches:
# - main
paths-ignore:
- '.github/dependabot.yml'
- '.github/pull_request_template.md'
- '.github/release.yml'
- 'README.md'
# NO paths-ignore
workflow_dispatch:
inputs: {}

# NOTE: 連続で commit & push した時に最新の commit 以外のワークフローをキャンセルする
concurrency:
Expand All @@ -40,8 +29,29 @@ defaults:
shell: bash

jobs:
go-lint: # NOTE: for Branch protection rule `Status checks that are required.`
runs-on: ubuntu-latest # ref. https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-syntax-for-github-actions#jobsjob_idruns-on
paths-ignore:
runs-on: ubuntu-latest
outputs:
skip: ${{ steps.paths-ignore.outputs.skip }}
steps:
- uses: kunitsucom/[email protected]
id: paths-ignore
with:
paths-ignore: |-
# substrings of file paths to ignore written in regular expressions
^.github/dependabot.yml$
^.github/pull_request_template.md$
^.github/release.yml$
^.github/workflows/label-checker.yml$
^.github/workflows/task-list-checker.yml$
^.*\.md$
# > Note: A job that is skipped will report its status as "Success".
# > It will not prevent a pull request from merging, even if it is a required check.
# ref. https://docs.github.com/en/actions/using-jobs/using-conditions-to-control-job-execution#overview
go-lint:
runs-on: ubuntu-latest
needs: paths-ignore
if: ${{ needs.paths-ignore.outputs.skip != 'true' }}
steps:
- uses: actions/checkout@v4
- name: DEBUG
Expand Down
40 changes: 25 additions & 15 deletions .github/workflows/go-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,10 @@ on:
push:
branches:
- main
paths-ignore:
- '.github/dependabot.yml'
- '.github/pull_request_template.md'
- '.github/release.yml'
- 'README.md'
# NO paths-ignore
pull_request:
# branches:
# - main
paths-ignore:
- '.github/dependabot.yml'
- '.github/pull_request_template.md'
- '.github/release.yml'
- 'README.md'
# NO paths-ignore
workflow_dispatch:
inputs: {}

# NOTE: 連続で commit & push した時に最新の commit 以外のワークフローをキャンセルする
concurrency:
Expand All @@ -40,8 +29,29 @@ defaults:
shell: bash

jobs:
go-test: # NOTE: for Branch protection rule `Status checks that are required.`
runs-on: ubuntu-latest # ref. https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-syntax-for-github-actions#jobsjob_idruns-on
paths-ignore:
runs-on: ubuntu-latest
outputs:
skip: ${{ steps.paths-ignore.outputs.skip }}
steps:
- uses: kunitsucom/[email protected]
id: paths-ignore
with:
paths-ignore: |-
# substrings of file paths to ignore written in regular expressions
^.github/dependabot.yml$
^.github/pull_request_template.md$
^.github/release.yml$
^.github/workflows/label-checker.yml$
^.github/workflows/task-list-checker.yml$
^.*\.md$
# > Note: A job that is skipped will report its status as "Success".
# > It will not prevent a pull request from merging, even if it is a required check.
# ref. https://docs.github.com/en/actions/using-jobs/using-conditions-to-control-job-execution#overview
go-test:
runs-on: ubuntu-latest
needs: paths-ignore
if: ${{ needs.paths-ignore.outputs.skip != 'true' }}
steps:
- uses: actions/checkout@v4
- name: DEBUG
Expand Down
78 changes: 78 additions & 0 deletions .github/workflows/label-checker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
name: label-checker

# Dependabot
# gh label create --force "dependencies" --description "Pull requests that update a dependency file" --color 0366D6
# gh label create --force "go" --description "Pull requests that update Go code" --color 16E2E2
# gh label create --force "github_actions" --description "Pull requests that update GitHub Actions code" --color 000000
# gh label create --force "docker" --description "Pull requests that update Docker code" --color 21CEFF

# Commit prefix
# gh label create --force "BREAKING CHANGE" --description "BREAKING CHANGES" --color FF0303
# gh label create --force "build" --description "Changes that affect the build system or external dependencies (example scopes: gulp, broccoli, npm)" --color 5319E7
# gh label create --force "ci" --description "Changes to our CI configuration files and scripts (examples: CircleCi, SauceLabs)" --color 53C4EE
# gh label create --force "docs" --description "Documentation only changes" --color 1B3E44
# gh label create --force "feat" --description "A new feature" --color 0EAA80
# gh label create --force "fix" --description "A bug fix" --color 1D76DB
# gh label create --force "perf" --description "A code change that improves performance" --color A2EEEF
# gh label create --force "refactor" --description "A code change that neither fixes a bug nor adds a feature" --color C5DEF5
# gh label create --force "test" --description "Adding missing tests or correcting existing tests" --color 1D76DB
# gh label create --force "chore" --description "Changes to the build process or auxiliary tools and libraries such as documentation generation" --color 20313F

on:
pull_request:
types:
- opened
- edited
- labeled
- unlabeled
- ready_for_review
- reopened
- synchronize

env:
LABELS: "BREAKING CHANGE,build,ci,docs,feat,fix,perf,refactor,test,chore"

jobs:
check:
name: Check labels
runs-on: ubuntu-latest
timeout-minutes: 10
permissions:
id-token: write
contents: read
pull-requests: write # required to add labels
statuses: read
checks: read
repository-projects: read
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.ref }} # needed for gh pr view
- name: Check labels
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
shell: bash
run: |
# Check labels
set -Eeuo pipefail -x
# If any of the labels are present, exit with success
if [[ -n "$(gh pr view --json labels --jq ".labels[].name" | grep -E "^($(tr , "|" <<<"${LABELS:?}"))$")" ]]; then
exit 0
fi
# Add labels based on PR title
GH_PR_TITLE=$(gh pr view --json title --jq .title)
gh label list --json name --jq ".[].name" | while read -r LINE; do
awk -F: "/^${LINE-}(\([^\)]+\))?:/ {print \$1}" <<<"${GH_PR_TITLE:?}" | grep -Eo "^${LINE:?}" || true # NOTE: Ignore the return value of grep because we just want to output the string
done | xargs -t -I{} gh pr edit --add-label {}
# If any of the labels are present, exit with success
while read -r LINE; do
if grep -E "^($(tr , "|" <<<"${LABELS:?}"))$" <<<"${LINE-}"; then
exit 0
fi
done <<<"$(gh pr view --json labels --jq ".labels[].name")"
# If none of the labels are present, exit with error
exit 1
29 changes: 29 additions & 0 deletions .github/workflows/task-list-checker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: task-list-checker

on:
pull_request:
types:
- opened
- edited
- ready_for_review
- reopened
- synchronize

jobs:
check:
name: Check task list
runs-on: ubuntu-latest
timeout-minutes: 10
permissions:
id-token: write
contents: read
pull-requests: read
statuses: write
defaults:
run:
shell: bash
steps:
- name: Check for incomplete task list items
uses: Shopify/task-list-checker@7cab3e5a969a34f8c553974bc6f8940d8c3978de # ref. https://github.com/Shopify/task-list-checker
with:
github-token: ${{ secrets.GITHUB_TOKEN }}

0 comments on commit 0329cf9

Please sign in to comment.