Skip to content

Commit

Permalink
Fix copyright-check script
Browse files Browse the repository at this point in the history
  • Loading branch information
F3Joule committed Oct 31, 2023
1 parent 75991d5 commit 2ac230a
Showing 1 changed file with 31 additions and 19 deletions.
50 changes: 31 additions & 19 deletions .github/workflows/copyright-check.yml
Original file line number Diff line number Diff line change
@@ -1,52 +1,64 @@
name: Check and add copyright
name: Copyright checker

on:
pull_request:
branches:
- main
issue_comment:
types: [created]
push:

env:
PLATFORM: ubuntu-latest
GO_VERSION: 1.16.x

jobs:
copyright-check:
strategy:
matrix:
platform: [ ubuntu-latest ]
go-version: [ 1.16.x ]

runs-on: ${{ matrix.platform }}
runs-on: ${{ env.PLATFORM }}

steps:
- name: Setup Go
uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go-version }}
go-version: ${{ env.GO_VERSION }}

- name: Install addlicense
run: |
go install github.com/google/addlicense@latest
- name: Checkout repository
uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.sha }}
persist-credentials: false
fetch-depth: 0

# Check license notice in all files
- name: Copyright Check
id: check
continue-on-error: true
run: .maintain/add_license.sh -check

copyright-add:
needs: [copyright-check]
if: contains(github.event.comment.html_url, '/pull/') && contains(github.event.comment.body, '/addlicense')
runs-on: ${{ env.PLATFORM }}

steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.sha }}
persist-credentials: false
fetch-depth: 0

- name: Setup Go
uses: actions/setup-go@v3
with:
go-version: ${{ env.GO_VERSION }}

# Add license if check fails
- name: Add copyright notice
if: steps.check.outcome == 'failure'
if: jobs.copyright-check.steps.outcome == 'failure'
run: |
.maintain/add_license.sh
remote_repo="https://${GITHUB_ACTOR}:${{ secrets.GITHUB_TOKEN }}@github.com/${GITHUB_REPOSITORY}.git"
git config http.sslVerify false
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git add -A
git commit -m "Add missing license headers"
git push "${remote_repo}" HEAD:${{ github.head_ref }}
git push "${remote_repo}" HEAD:${{ github.head_ref }}

0 comments on commit 2ac230a

Please sign in to comment.