| 1 |
name: '[CI/CD] Go' |
| 2 |
|
| 3 |
on: |
| 4 |
pull_request: |
| 5 |
branches: |
| 6 |
- main |
| 7 |
paths: |
| 8 |
- 'pkg/**' |
| 9 |
push: |
| 10 |
branches: |
| 11 |
- main |
| 12 |
paths: |
| 13 |
- 'pkg/**' |
| 14 |
|
| 15 |
# Remove all permissions by default |
| 16 |
permissions: {} |
| 17 |
jobs: |
| 18 |
test: |
| 19 |
runs-on: ubuntu-latest |
| 20 |
permissions: |
| 21 |
contents: write |
| 22 |
steps: |
| 23 |
- name: Checkout |
| 24 |
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
| 25 |
|
| 26 |
- name: Set up Go |
| 27 |
uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0 |
| 28 |
with: |
| 29 |
go-version: '1.20' |
| 30 |
|
| 31 |
- name: Get changed src code |
| 32 |
id: changed-files |
| 33 |
uses: tj-actions/changed-files@9426d40962ed5378910ee2e21d5f8c6fcbf2dd96 # v47.0.6 |
| 34 |
with: |
| 35 |
dir_names: "true" |
| 36 |
dir_names_max_depth: "2" |
| 37 |
files: | |
| 38 |
pkg/** |
| 39 |
|
| 40 |
- name: Test |
| 41 |
if: steps.changed-files.outputs.any_changed == 'true' |
| 42 |
run: | |
| 43 |
for dir in ${{ steps.changed-files.outputs.all_changed_files }}; do |
| 44 |
go test -v ./${dir}/... |
| 45 |
done |
| 46 |
|
| 47 |
check: |
| 48 |
runs-on: ubuntu-latest |
| 49 |
permissions: |
| 50 |
contents: write |
| 51 |
steps: |
| 52 |
- name: Checkout |
| 53 |
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
| 54 |
|
| 55 |
- name: Set up Go |
| 56 |
uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0 |
| 57 |
with: |
| 58 |
go-version: '1.20' |
| 59 |
|
| 60 |
- name: Get changed src code |
| 61 |
id: changed-files |
| 62 |
uses: tj-actions/changed-files@9426d40962ed5378910ee2e21d5f8c6fcbf2dd96 # v47.0.6 |
| 63 |
with: |
| 64 |
dir_names: "true" |
| 65 |
dir_names_max_depth: "2" |
| 66 |
files: | |
| 67 |
pkg/** |
| 68 |
|
| 69 |
- name: Format |
| 70 |
if: steps.changed-files.outputs.any_changed == 'true' |
| 71 |
run: | |
| 72 |
exit_code=0 |
| 73 |
for dir in ${{ steps.changed-files.outputs.all_changed_files }}; do |
| 74 |
if [ "$(gofmt -s -l ./${dir} | wc -l)" -gt 0 ]; then |
| 75 |
exit_code=1 |
| 76 |
fi |
| 77 |
done |
| 78 |
exit $exit_code |
| 79 |
|
| 80 |
- name: golangci-lint |
| 81 |
uses: golangci/golangci-lint-action@1e7e51e771db61008b38414a730f564565cf7c20 # v9.2.0 |
| 82 |
with: |
| 83 |
args: "--out-${NO_FUTURE}format colored-line-number" |
| 84 |
only-new-issues: true |
| 85 |
skip-cache: true |
| 86 |
skip-build-cache: true |
| 87 |
version: latest |