|
| 1 | +# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/check-go-task.md |
| 2 | +name: Check Go |
| 3 | + |
| 4 | +env: |
| 5 | + # See: https://github.com/actions/setup-go/tree/v2#readme |
| 6 | + GO_VERSION: "1.16" |
| 7 | + |
| 8 | +# See: https://docs.github.com/en/actions/reference/events-that-trigger-workflows |
| 9 | +on: |
| 10 | + push: |
| 11 | + paths: |
| 12 | + - ".github/workflows/check-go-task.ya?ml" |
| 13 | + - "Taskfile.ya?ml" |
| 14 | + - "go.mod" |
| 15 | + - "go.sum" |
| 16 | + - "**.go" |
| 17 | + pull_request: |
| 18 | + paths: |
| 19 | + - ".github/workflows/check-go-task.ya?ml" |
| 20 | + - "Taskfile.ya?ml" |
| 21 | + - "go.mod" |
| 22 | + - "go.sum" |
| 23 | + - "**.go" |
| 24 | + workflow_dispatch: |
| 25 | + repository_dispatch: |
| 26 | + |
| 27 | +jobs: |
| 28 | + check-errors: |
| 29 | + runs-on: ubuntu-latest |
| 30 | + |
| 31 | + steps: |
| 32 | + - name: Checkout repository |
| 33 | + uses: actions/checkout@v2 |
| 34 | + |
| 35 | + - name: Install Go |
| 36 | + uses: actions/setup-go@v2 |
| 37 | + with: |
| 38 | + go-version: ${{ env.GO_VERSION }} |
| 39 | + |
| 40 | + - name: Install Task |
| 41 | + uses: arduino/setup-task@v1 |
| 42 | + with: |
| 43 | + repo-token: ${{ secrets.GITHUB_TOKEN }} |
| 44 | + version: 3.x |
| 45 | + |
| 46 | + - name: Check for errors |
| 47 | + run: task go:vet |
| 48 | + |
| 49 | + check-outdated: |
| 50 | + runs-on: ubuntu-latest |
| 51 | + |
| 52 | + steps: |
| 53 | + - name: Checkout repository |
| 54 | + uses: actions/checkout@v2 |
| 55 | + |
| 56 | + - name: Install Go |
| 57 | + uses: actions/setup-go@v2 |
| 58 | + with: |
| 59 | + go-version: ${{ env.GO_VERSION }} |
| 60 | + |
| 61 | + - name: Install Task |
| 62 | + uses: arduino/setup-task@v1 |
| 63 | + with: |
| 64 | + repo-token: ${{ secrets.GITHUB_TOKEN }} |
| 65 | + version: 3.x |
| 66 | + |
| 67 | + - name: Modernize usages of outdated APIs |
| 68 | + run: task go:fix |
| 69 | + |
| 70 | + - name: Check if any fixes were needed |
| 71 | + run: git diff --color --exit-code |
| 72 | + |
| 73 | + check-style: |
| 74 | + runs-on: ubuntu-latest |
| 75 | + |
| 76 | + steps: |
| 77 | + - name: Checkout repository |
| 78 | + uses: actions/checkout@v2 |
| 79 | + |
| 80 | + - name: Install Go |
| 81 | + uses: actions/setup-go@v2 |
| 82 | + with: |
| 83 | + go-version: ${{ env.GO_VERSION }} |
| 84 | + |
| 85 | + - name: Install Task |
| 86 | + uses: arduino/setup-task@v1 |
| 87 | + with: |
| 88 | + repo-token: ${{ secrets.GITHUB_TOKEN }} |
| 89 | + version: 3.x |
| 90 | + |
| 91 | + - name: Install golint |
| 92 | + run: go install golang.org/x/lint/golint@latest |
| 93 | + |
| 94 | + - name: Check style |
| 95 | + run: task --silent go:lint |
| 96 | + |
| 97 | + check-formatting: |
| 98 | + runs-on: ubuntu-latest |
| 99 | + |
| 100 | + steps: |
| 101 | + - name: Checkout repository |
| 102 | + uses: actions/checkout@v2 |
| 103 | + |
| 104 | + - name: Install Go |
| 105 | + uses: actions/setup-go@v2 |
| 106 | + with: |
| 107 | + go-version: ${{ env.GO_VERSION }} |
| 108 | + |
| 109 | + - name: Install Task |
| 110 | + uses: arduino/setup-task@v1 |
| 111 | + with: |
| 112 | + repo-token: ${{ secrets.GITHUB_TOKEN }} |
| 113 | + version: 3.x |
| 114 | + |
| 115 | + - name: Format code |
| 116 | + run: task go:format |
| 117 | + |
| 118 | + - name: Check formatting |
| 119 | + run: git diff --color --exit-code |
| 120 | + |
| 121 | + check-config: |
| 122 | + name: check-config (${{ matrix.module.path }}) |
| 123 | + runs-on: ubuntu-latest |
| 124 | + |
| 125 | + strategy: |
| 126 | + fail-fast: false |
| 127 | + |
| 128 | + matrix: |
| 129 | + module: |
| 130 | + - path: ./ |
| 131 | + |
| 132 | + steps: |
| 133 | + - name: Checkout repository |
| 134 | + uses: actions/checkout@v2 |
| 135 | + |
| 136 | + - name: Install Go |
| 137 | + uses: actions/setup-go@v2 |
| 138 | + with: |
| 139 | + go-version: ${{ env.GO_VERSION }} |
| 140 | + |
| 141 | + - name: Run go mod tidy |
| 142 | + working-directory: ${{ matrix.module.path }} |
| 143 | + run: go mod tidy |
| 144 | + |
| 145 | + - name: Check whether any tidying was needed |
| 146 | + run: git diff --color --exit-code |
0 commit comments