diff --git a/.github/workflows/commit-lint.yml b/.github/workflows/commit-lint.yml new file mode 100644 index 0000000..10f644e --- /dev/null +++ b/.github/workflows/commit-lint.yml @@ -0,0 +1,40 @@ +name: Lint Commit Messages +on: push + +jobs: + commit-lint: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Use Node.js + uses: actions/setup-node@v4 + + - name: Install commitlint + run: | + npm install --save-dev @commitlint/{config-conventional,cli} + + - name: Lint commits + run: | + npx commitlint --from=HEAD~1 --to=HEAD --config ./.github/workflows/configs/commitlint.config.js + + check-dontmerge: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Check for DONTMERGE + run: | + result=$(find . \ + -type f \ + ! -path './.github/workflows/commit-lint.yml' \ + ! -name '*.snap' \ + -exec grep -Hn 'DONTMERGE' {} \;) + if [[ ! -z "$result" ]]; then + echo "$result" + exit 1 + fi diff --git a/.github/workflows/configs/commitlint.config.js b/.github/workflows/configs/commitlint.config.js new file mode 100644 index 0000000..335f922 --- /dev/null +++ b/.github/workflows/configs/commitlint.config.js @@ -0,0 +1,22 @@ +module.exports = { + rules: { + 'type-enum': [ + 2, + 'always', + [ + 'build', + 'chore', + 'ci', + 'docs', + 'feat', + 'fix', + 'perf', + 'refactor', + 'revert', + 'style', + 'test', + 'autogen', + ] + ], + } +}; diff --git a/.github/workflows/create-pr.yml b/.github/workflows/create-pr.yml index d3be756..8e97978 100644 --- a/.github/workflows/create-pr.yml +++ b/.github/workflows/create-pr.yml @@ -1,16 +1,64 @@ -name: Run the Action on each commit +name: Create PR + on: push: - branches-ignore: main + branches-ignore: + - main + jobs: - action-pull-request: + create_and_enable_automerge: runs-on: ubuntu-latest steps: - name: Checkout repository uses: actions/checkout@v4 - - name: Create pull request - uses: devops-infra/action-pull-request@v0.5.5 + + - name: Set branch name as output + id: branch_name + run: echo "::set-output name=branch::${GITHUB_REF#refs/heads/}" + + - name: Create Pull Request + id: create_pr + uses: repo-sync/pull-request@v2 with: - github_token: ${{ secrets.GITHUB_TOKEN }} - reviewer: HiromiShikata - target_branch: main + github_token: ${{ secrets.GH_TOKEN }} + destination_branch: 'main' + source_branch: '' + pr_title: '${{ steps.branch_name.outputs.branch }}' + pr_body: 'This is an auto-create PR.' + draft: false + + - name: Assign PR to author + if: steps.create_pr.outputs.pr_number + run: | + curl -s -X POST \ + -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ + -H "Accept: application/vnd.github.v3+json" \ + -d '{"assignees":["${{ github.actor }}"]}' \ + "https://api.github.com/repos/${{ github.repository }}/issues/${{ steps.create_pr.outputs.pr_number }}/assignees" + + - name: Get PR Node ID + if: steps.create_pr.outputs.pr_number + id: get_pr_id + run: | + PR_DATA=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" -H "Accept: application/vnd.github.v3+json" "https://api.github.com/repos/${{ github.repository }}/pulls/${{ steps.create_pr.outputs.pr_number }}") + PR_ID=$(echo "$PR_DATA" | jq -r '.node_id') + echo "::set-output name=node_id::$PR_ID" + + - name: Enable Auto Merge for PR + if: steps.create_pr.outputs.pr_number + run: | + RESPONSE=$(curl -s -X POST \ + -H "Authorization: bearer ${{ secrets.GH_TOKEN }}" \ + -H "Content-Type: application/json" \ + -d '{ + "query": "mutation($id: ID!) { enablePullRequestAutoMerge(input: { pullRequestId: $id }) { clientMutationId } }", + "variables": { + "id": "'"${{ steps.get_pr_id.outputs.node_id }}"'" + } + }' \ + "https://api.github.com/graphql") + echo "$RESPONSE" + if echo "$RESPONSE" | jq -e '.errors' >/dev/null; then + echo "Failed to enable auto merge" + exit 1 + fi diff --git a/.github/workflows/empty-format-test-job.yml b/.github/workflows/empty-format-test-job.yml new file mode 100644 index 0000000..7955c06 --- /dev/null +++ b/.github/workflows/empty-format-test-job.yml @@ -0,0 +1,15 @@ +name: Empty format test + +on: + push + +jobs: + format: + runs-on: ubuntu-latest + steps: + - run: echo "format" + test: + runs-on: ubuntu-latest + steps: + - run: echo "test" + diff --git a/.github/workflows/umino-project.yml b/.github/workflows/umino-project.yml index 794f531..297552e 100644 --- a/.github/workflows/umino-project.yml +++ b/.github/workflows/umino-project.yml @@ -6,6 +6,7 @@ on: - reopened - assigned - unassigned + - labeled pull_request: types: - opened @@ -13,6 +14,7 @@ on: - review_requested - assigned - unassigned + - labeled env: inbox: Inbox @@ -22,14 +24,15 @@ env: project_id: 48 jobs: - move_to_inbox: + umino-job: name: opened_or_reopened runs-on: ubuntu-latest if: >- (github.event_name == 'issues' && github.event.issue.state == 'open') || (github.event_name == 'pull_request' && github.event.pull_request.state == 'open') && (github.event.action == 'opened' || github.event.action == 'reopened' || - github.event.action == 'assigned' || github.event.action == 'unassigned') + github.event.action == 'assigned' || github.event.action == 'unassigned' || + (github.event.action == 'labeled' && github.event.label.name == 'hiromishikata:task:offline')) steps: - name: Move issue to ${{ env.inbox }} uses: leonsteinhaeuser/project-beta-automations@v2.2.1 @@ -39,3 +42,16 @@ jobs: project_id: ${{ env.project_id }} resource_node_id: ${{ github.event.pull_request.node_id || github.event.issue.node_id }} status_value: ${{ env.inbox }} + - name: Comment #offline + if: github.event_name == 'issues' && github.event.action == 'labeled' && github.event.label.name == 'hiromishikata:task:offline' + uses: actions/github-script@v7 + with: + github-token: ${{secrets.GITHUB_TOKEN}} + script: | + const issueComment = { + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.issue.number, + body: '#offline' + }; + github.issues.createComment(issueComment);