Skip to content

gha(deps): bump actions/upload-artifact from 3 to 4 #93

gha(deps): bump actions/upload-artifact from 3 to 4

gha(deps): bump actions/upload-artifact from 3 to 4 #93

Workflow file for this run

name: Golang CI
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
types: [opened, synchronize]
#defaults:
# run:
# shell: bash
# working-directory: src
jobs:
avoid_reduncy:
name: Cancel Previous Pipelines
runs-on: ubuntu-latest
steps:
- name: Cancel Workflow
uses: styfle/[email protected]
lint:
name: Lint with Go ${{ matrix.go-version }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
env:
working-directory: ./src
artifact-path: ${{ github.workspace }}/src
strategy:
matrix:
os:
# - ubuntu-18.04
# - ubuntu-20.04
- ubuntu-latest
# - windows-latest
# - macos-latest
go-version:
# Latest n versions
# - 1.15
- 1.16
# - 1.17
steps:
- name: Install Go
uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go-version }}
check-latest: true
- name: Verify Go
run: go version
- name: Install dependencies
run: |
go get -v -u golang.org/x/tools/cmd/goimports
- name: Checkout code
uses: actions/checkout@v4
- name: Restore cache
uses: actions/cache@v3
with:
# In order:
# * Module download cache
# * Build cache (Linux)
# * Build cache (Mac)
# * Build cache (Windows)
path: |
~/go/pkg/mod
~/.cache/go-build
~/Library/Caches/go-build
%LocalAppData%\go-build
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Check code formats (gofmt)
id: check-gofmt
run: |
FILES=$(gofmt -l -s .)
FILES_COUNT=$(gofmt -l -s . | wc -l)
if [ "$FILES_COUNT" -gt 0 ]; then
echo -e "::warning::There are $FILES_COUNT files to be reformatted:\n\n$FILES\n\n"
gofmt -d -s -e . > ${{ env.working-directory }}/gofmt-${{ matrix.go-version }}-${{ matrix.os }}.diff
fi
echo -e "::set-output name=files::$FILES" > /dev/null
echo "::set-output name=count::$FILES_COUNT"
- name: Save gofmt artifact
# if: ${{ toJSON(job.steps.check-gofmt.outputs.count) > 0 }}
uses: actions/upload-artifact@v4
with:
name: gofmt-outputs-${{ matrix.go-version }}-${{ matrix.os }}
path: |
${{ env.artifact-path }}
!**/goimports-*.diff
if-no-files-found: warn
retention-days: 5
- name: Check code formats (goimports)
id: check-goimports
run: |
FILES=$(goimports -l .)
FILES_COUNT=$(goimports -l . | wc -l)
if [ "$FILES_COUNT" -gt 0 ]; then
echo -en "::warning::There are $FILES_COUNT files with import changes:\n\n$FILES\n\n"
goimports -d . > ${{ env.working-directory }}/goimports-${{ matrix.go-version }}-${{ matrix.os }}.diff
fi
echo -e "::set-output name=files::$FILES" > /dev/null
echo "::set-output name=count::$FILES_COUNT"
- name: Save goimports artifact
# if: ${{ toJSON(job.steps.check-goimports.outputs.count) > 0 }}
uses: actions/upload-artifact@v4
with:
name: goimports-outputs-${{ matrix.go-version }}-${{ matrix.os }}
path: |
${{ env.artifact-path }}
!**/gofmt-*.diff
if-no-files-found: warn
retention-days: 5
# - name: Fix code formats
# run: find . -name '*.go' | while read -r file; do gofmt -s -w "$$file"; goimports -w "$$file"; done
# if: startsWith(matrix.os, 'ubuntu-')
# - name: Ensure code formats
# run: if [ "$(gofmt -s -l . | wc -l)" -gt 0 ]; then exit 1; fi
# if: startsWith(matrix.os, 'ubuntu-')
# - name: Build
# run: go build -v ./...
# - name: Test
# run: go test -v -race ./...