ci: add Go modules/build cache, fix master branch triggers
- Add actions/cache@v4 for GOMODCACHE and GOCACHE on lint/test/build - Switch from setup-go built-in cache to explicit cache control - Fix branch refs: main → master for PR, artifact, and docker jobs - Use registry-based Docker layer caching (mode=max) - Extract GO_VERSION env var for single-point version management
This commit is contained in:
@@ -4,7 +4,10 @@ on:
|
||||
push:
|
||||
branches: ["**"]
|
||||
pull_request:
|
||||
branches: ["main"]
|
||||
branches: ["master"]
|
||||
|
||||
env:
|
||||
GO_VERSION: "1.25"
|
||||
|
||||
jobs:
|
||||
lint:
|
||||
@@ -14,7 +17,17 @@ jobs:
|
||||
|
||||
- uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: "1.25"
|
||||
go-version: ${{ env.GO_VERSION }}
|
||||
|
||||
- name: Cache Go modules
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: |
|
||||
~/go/pkg/mod
|
||||
~/.cache/go-build
|
||||
key: go-lint-${{ runner.os }}-${{ hashFiles('go.sum') }}
|
||||
restore-keys: |
|
||||
go-lint-${{ runner.os }}-
|
||||
|
||||
- name: Download Go modules
|
||||
run: go mod download
|
||||
@@ -39,7 +52,17 @@ jobs:
|
||||
|
||||
- uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: "1.25"
|
||||
go-version: ${{ env.GO_VERSION }}
|
||||
|
||||
- name: Cache Go modules and build cache
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: |
|
||||
~/go/pkg/mod
|
||||
~/.cache/go-build
|
||||
key: go-test-${{ runner.os }}-${{ hashFiles('go.sum') }}
|
||||
restore-keys: |
|
||||
go-test-${{ runner.os }}-
|
||||
|
||||
- name: Download Go modules
|
||||
run: go mod download
|
||||
@@ -55,14 +78,26 @@ jobs:
|
||||
|
||||
- uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: "1.25"
|
||||
cache: true
|
||||
go-version: ${{ env.GO_VERSION }}
|
||||
|
||||
- name: Cache Go modules and build cache
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: |
|
||||
~/go/pkg/mod
|
||||
~/.cache/go-build
|
||||
key: go-build-${{ runner.os }}-${{ hashFiles('go.sum') }}
|
||||
restore-keys: |
|
||||
go-build-${{ runner.os }}-
|
||||
|
||||
- name: Download Go modules
|
||||
run: go mod download
|
||||
|
||||
- name: Build binary
|
||||
run: go build -o mrixscraft-server ./cmd/server
|
||||
|
||||
- name: Upload artifact
|
||||
if: github.ref == 'refs/heads/main'
|
||||
if: github.ref == 'refs/heads/master'
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: mrixscraft-server
|
||||
@@ -71,7 +106,7 @@ jobs:
|
||||
docker:
|
||||
runs-on: ubuntu-latest
|
||||
needs: build
|
||||
if: github.ref == 'refs/heads/main'
|
||||
if: github.ref == 'refs/heads/master'
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
@@ -93,5 +128,5 @@ jobs:
|
||||
tags: |
|
||||
gitea.mrixs.me/Mrixs/MrixsCraft-server:latest
|
||||
gitea.mrixs.me/Mrixs/MrixsCraft-server:${{ github.sha }}
|
||||
cache-from: type=registry,ref=gitea.mrixs.me/Mrixs/MrixsCraft-server:latest
|
||||
cache-to: type=inline
|
||||
cache-from: type=registry,ref=gitea.mrixs.me/Mrixs/MrixsCraft-server:buildcache
|
||||
cache-to: type=registry,ref=gitea.mrixs.me/Mrixs/MrixsCraft-server:buildcache,mode=max
|
||||
|
||||
Reference in New Issue
Block a user