|
| 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/main#supported-version-syntax |
| 6 | + GO_VERSION: "1.19" |
| 7 | + |
| 8 | +# See: https://docs.github.com/actions/using-workflows/events-that-trigger-workflows |
| 9 | +on: |
| 10 | + create: |
| 11 | + push: |
| 12 | + paths: |
| 13 | + - ".github/workflows/check-go-task.ya?ml" |
| 14 | + - "Taskfile.ya?ml" |
| 15 | + - "**/go.mod" |
| 16 | + - "**/go.sum" |
| 17 | + - "**.go" |
| 18 | + pull_request: |
| 19 | + paths: |
| 20 | + - ".github/workflows/check-go-task.ya?ml" |
| 21 | + - "Taskfile.ya?ml" |
| 22 | + - "**/go.mod" |
| 23 | + - "**/go.sum" |
| 24 | + - "**.go" |
| 25 | + schedule: |
| 26 | + # Run periodically to catch breakage caused by external changes. |
| 27 | + - cron: "0 7 * * WED" |
| 28 | + workflow_dispatch: |
| 29 | + repository_dispatch: |
| 30 | + |
| 31 | +jobs: |
| 32 | + run-determination: |
| 33 | + runs-on: ubuntu-latest |
| 34 | + outputs: |
| 35 | + result: ${{ steps.determination.outputs.result }} |
| 36 | + steps: |
| 37 | + - name: Determine if the rest of the workflow should run |
| 38 | + id: determination |
| 39 | + run: | |
| 40 | + RELEASE_BRANCH_REGEX="refs/heads/[0-9]+.[0-9]+.x" |
| 41 | + # The `create` event trigger doesn't support `branches` filters, so it's necessary to use Bash instead. |
| 42 | + if [[ |
| 43 | + "${{ github.event_name }}" != "create" || |
| 44 | + "${{ github.ref }}" =~ $RELEASE_BRANCH_REGEX |
| 45 | + ]]; then |
| 46 | + # Run the other jobs. |
| 47 | + RESULT="true" |
| 48 | + else |
| 49 | + # There is no need to run the other jobs. |
| 50 | + RESULT="false" |
| 51 | + fi |
| 52 | +
|
| 53 | + echo "result=$RESULT" >> $GITHUB_OUTPUT |
| 54 | +
|
| 55 | + check-errors: |
| 56 | + name: check-errors (${{ matrix.module.path }}) |
| 57 | + needs: run-determination |
| 58 | + if: needs.run-determination.outputs.result == 'true' |
| 59 | + runs-on: ubuntu-latest |
| 60 | + |
| 61 | + strategy: |
| 62 | + fail-fast: false |
| 63 | + |
| 64 | + matrix: |
| 65 | + module: |
| 66 | + # TODO: add paths of all Go modules here |
| 67 | + - path: ./ |
| 68 | + |
| 69 | + steps: |
| 70 | + - name: Checkout repository |
| 71 | + uses: actions/checkout@v3 |
| 72 | + |
| 73 | + - name: Install Go |
| 74 | + uses: actions/setup-go@v3 |
| 75 | + with: |
| 76 | + go-version: ${{ env.GO_VERSION }} |
| 77 | + |
| 78 | + - name: Install Task |
| 79 | + uses: arduino/setup-task@v1 |
| 80 | + with: |
| 81 | + repo-token: ${{ secrets.GITHUB_TOKEN }} |
| 82 | + version: 3.x |
| 83 | + |
| 84 | + - name: Install Dependencies |
| 85 | + run: sudo apt update && sudo apt install -y --no-install-recommends build-essential libgtk-3-dev libwebkit2gtk-4.0-dev libappindicator3-dev |
| 86 | + |
| 87 | + - name: Check for errors |
| 88 | + env: |
| 89 | + GO_MODULE_PATH: ${{ matrix.module.path }} |
| 90 | + run: task go:vet |
| 91 | + |
| 92 | + check-outdated: |
| 93 | + name: check-outdated (${{ matrix.module.path }}) |
| 94 | + needs: run-determination |
| 95 | + if: needs.run-determination.outputs.result == 'true' |
| 96 | + runs-on: ubuntu-latest |
| 97 | + |
| 98 | + strategy: |
| 99 | + fail-fast: false |
| 100 | + |
| 101 | + matrix: |
| 102 | + module: |
| 103 | + # TODO: add paths of all Go modules here |
| 104 | + - path: ./ |
| 105 | + |
| 106 | + steps: |
| 107 | + - name: Checkout repository |
| 108 | + uses: actions/checkout@v3 |
| 109 | + |
| 110 | + - name: Install Go |
| 111 | + uses: actions/setup-go@v3 |
| 112 | + with: |
| 113 | + go-version: ${{ env.GO_VERSION }} |
| 114 | + |
| 115 | + - name: Install Task |
| 116 | + uses: arduino/setup-task@v1 |
| 117 | + with: |
| 118 | + repo-token: ${{ secrets.GITHUB_TOKEN }} |
| 119 | + version: 3.x |
| 120 | + |
| 121 | + - name: Modernize usages of outdated APIs |
| 122 | + env: |
| 123 | + GO_MODULE_PATH: ${{ matrix.module.path }} |
| 124 | + run: task go:fix |
| 125 | + |
| 126 | + - name: Check if any fixes were needed |
| 127 | + run: git diff --color --exit-code |
| 128 | + |
| 129 | + check-style: |
| 130 | + name: check-style (${{ matrix.module.path }}) |
| 131 | + needs: run-determination |
| 132 | + if: needs.run-determination.outputs.result == 'true' |
| 133 | + runs-on: ubuntu-latest |
| 134 | + |
| 135 | + strategy: |
| 136 | + fail-fast: false |
| 137 | + |
| 138 | + matrix: |
| 139 | + module: |
| 140 | + # TODO: add paths of all Go modules here |
| 141 | + - path: ./ |
| 142 | + |
| 143 | + steps: |
| 144 | + - name: Checkout repository |
| 145 | + uses: actions/checkout@v3 |
| 146 | + |
| 147 | + - name: Install Go |
| 148 | + uses: actions/setup-go@v3 |
| 149 | + with: |
| 150 | + go-version: ${{ env.GO_VERSION }} |
| 151 | + |
| 152 | + - name: Install Task |
| 153 | + uses: arduino/setup-task@v1 |
| 154 | + with: |
| 155 | + repo-token: ${{ secrets.GITHUB_TOKEN }} |
| 156 | + version: 3.x |
| 157 | + |
| 158 | + - name: Install golint |
| 159 | + run: go install golang.org/x/lint/golint@latest |
| 160 | + |
| 161 | + - name: Check style |
| 162 | + env: |
| 163 | + GO_MODULE_PATH: ${{ matrix.module.path }} |
| 164 | + run: task --silent go:lint |
| 165 | + |
| 166 | + check-formatting: |
| 167 | + name: check-formatting (${{ matrix.module.path }}) |
| 168 | + needs: run-determination |
| 169 | + if: needs.run-determination.outputs.result == 'true' |
| 170 | + runs-on: ubuntu-latest |
| 171 | + |
| 172 | + strategy: |
| 173 | + fail-fast: false |
| 174 | + |
| 175 | + matrix: |
| 176 | + module: |
| 177 | + # TODO: add paths of all Go modules here |
| 178 | + - path: ./ |
| 179 | + |
| 180 | + steps: |
| 181 | + - name: Checkout repository |
| 182 | + uses: actions/checkout@v3 |
| 183 | + |
| 184 | + - name: Install Go |
| 185 | + uses: actions/setup-go@v3 |
| 186 | + with: |
| 187 | + go-version: ${{ env.GO_VERSION }} |
| 188 | + |
| 189 | + - name: Install Task |
| 190 | + uses: arduino/setup-task@v1 |
| 191 | + with: |
| 192 | + repo-token: ${{ secrets.GITHUB_TOKEN }} |
| 193 | + version: 3.x |
| 194 | + |
| 195 | + - name: Format code |
| 196 | + env: |
| 197 | + GO_MODULE_PATH: ${{ matrix.module.path }} |
| 198 | + run: task go:format |
| 199 | + |
| 200 | + - name: Check formatting |
| 201 | + run: git diff --color --exit-code |
| 202 | + |
| 203 | + check-config: |
| 204 | + name: check-config (${{ matrix.module.path }}) |
| 205 | + needs: run-determination |
| 206 | + if: needs.run-determination.outputs.result == 'true' |
| 207 | + runs-on: ubuntu-latest |
| 208 | + |
| 209 | + strategy: |
| 210 | + fail-fast: false |
| 211 | + |
| 212 | + matrix: |
| 213 | + module: |
| 214 | + # TODO: add paths of all Go modules here |
| 215 | + - path: ./ |
| 216 | + |
| 217 | + steps: |
| 218 | + - name: Checkout repository |
| 219 | + uses: actions/checkout@v3 |
| 220 | + |
| 221 | + - name: Install Go |
| 222 | + uses: actions/setup-go@v3 |
| 223 | + with: |
| 224 | + go-version: ${{ env.GO_VERSION }} |
| 225 | + |
| 226 | + - name: Run go mod tidy |
| 227 | + working-directory: ${{ matrix.module.path }} |
| 228 | + run: go mod tidy |
| 229 | + |
| 230 | + - name: Check whether any tidying was needed |
| 231 | + run: git diff --color --exit-code |
0 commit comments