| 1 |
# Copyright 2022 Google LLC |
| 2 |
# |
| 3 |
# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 |
# you may not use this file except in compliance with the License. |
| 5 |
# You may obtain a copy of the License at |
| 6 |
# |
| 7 |
# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 |
# |
| 9 |
# Unless required by applicable law or agreed to in writing, software |
| 10 |
# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 |
# See the License for the specific language governing permissions and |
| 13 |
# limitations under the License. |
| 14 |
|
| 15 |
name: lint |
| 16 |
on: |
| 17 |
pull_request: |
| 18 |
pull_request_target: |
| 19 |
types: [labeled] |
| 20 |
|
| 21 |
jobs: |
| 22 |
lint: |
| 23 |
if: "${{ github.event.action != 'labeled' || github.event.label.name == 'tests: run' }}" |
| 24 |
name: run lint |
| 25 |
runs-on: ubuntu-latest |
| 26 |
steps: |
| 27 |
- name: Setup Go |
| 28 |
uses: actions/setup-go@v3 |
| 29 |
with: |
| 30 |
go-version: "1.21" |
| 31 |
- name: Install goimports |
| 32 |
run: go install golang.org/x/tools/cmd/goimports@latest |
| 33 |
- name: Checkout code |
| 34 |
uses: actions/checkout@v3 |
| 35 |
with: |
| 36 |
ref: ${{ github.event.pull_request.head.sha }} |
| 37 |
repository: ${{ github.event.pull_request.head.repo.full_name }} |
| 38 |
- run: goimports -w . |
| 39 |
- run: go mod tidy |
| 40 |
- name: Verify no changes from goimports and go mod tidy. If you're reading this and the check has failed, run `goimports -w . && go mod tidy`. |
| 41 |
run: git diff --exit-code |
| 42 |
- name: Remove PR Label |
| 43 |
if: "${{ github.event.action == 'labeled' && github.event.label.name == 'tests: run' }}" |
| 44 |
uses: actions/github-script@v6 |
| 45 |
with: |
| 46 |
github-token: ${{ secrets.GITHUB_TOKEN }} |
| 47 |
script: | |
| 48 |
try { |
| 49 |
await github.rest.issues.removeLabel({ |
| 50 |
name: 'tests: run', |
| 51 |
owner: context.repo.owner, |
| 52 |
repo: context.repo.repo, |
| 53 |
issue_number: context.payload.pull_request.number |
| 54 |
}); |
| 55 |
} catch (e) { |
| 56 |
console.log('Failed to remove label. Another job may have already removed it!'); |
| 57 |
} |