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