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:
|
push:
|
||||||
branches: ["**"]
|
branches: ["**"]
|
||||||
pull_request:
|
pull_request:
|
||||||
branches: ["main"]
|
branches: ["master"]
|
||||||
|
|
||||||
|
env:
|
||||||
|
GO_VERSION: "1.25"
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
lint:
|
lint:
|
||||||
@@ -14,7 +17,17 @@ jobs:
|
|||||||
|
|
||||||
- uses: actions/setup-go@v5
|
- uses: actions/setup-go@v5
|
||||||
with:
|
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
|
- name: Download Go modules
|
||||||
run: go mod download
|
run: go mod download
|
||||||
@@ -39,7 +52,17 @@ jobs:
|
|||||||
|
|
||||||
- uses: actions/setup-go@v5
|
- uses: actions/setup-go@v5
|
||||||
with:
|
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
|
- name: Download Go modules
|
||||||
run: go mod download
|
run: go mod download
|
||||||
@@ -55,14 +78,26 @@ jobs:
|
|||||||
|
|
||||||
- uses: actions/setup-go@v5
|
- uses: actions/setup-go@v5
|
||||||
with:
|
with:
|
||||||
go-version: "1.25"
|
go-version: ${{ env.GO_VERSION }}
|
||||||
cache: true
|
|
||||||
|
- 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
|
- name: Build binary
|
||||||
run: go build -o mrixscraft-server ./cmd/server
|
run: go build -o mrixscraft-server ./cmd/server
|
||||||
|
|
||||||
- name: Upload artifact
|
- name: Upload artifact
|
||||||
if: github.ref == 'refs/heads/main'
|
if: github.ref == 'refs/heads/master'
|
||||||
uses: actions/upload-artifact@v4
|
uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: mrixscraft-server
|
name: mrixscraft-server
|
||||||
@@ -71,7 +106,7 @@ jobs:
|
|||||||
docker:
|
docker:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
needs: build
|
needs: build
|
||||||
if: github.ref == 'refs/heads/main'
|
if: github.ref == 'refs/heads/master'
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
@@ -93,5 +128,5 @@ jobs:
|
|||||||
tags: |
|
tags: |
|
||||||
gitea.mrixs.me/Mrixs/MrixsCraft-server:latest
|
gitea.mrixs.me/Mrixs/MrixsCraft-server:latest
|
||||||
gitea.mrixs.me/Mrixs/MrixsCraft-server:${{ github.sha }}
|
gitea.mrixs.me/Mrixs/MrixsCraft-server:${{ github.sha }}
|
||||||
cache-from: type=registry,ref=gitea.mrixs.me/Mrixs/MrixsCraft-server:latest
|
cache-from: type=registry,ref=gitea.mrixs.me/Mrixs/MrixsCraft-server:buildcache
|
||||||
cache-to: type=inline
|
cache-to: type=registry,ref=gitea.mrixs.me/Mrixs/MrixsCraft-server:buildcache,mode=max
|
||||||
|
|||||||
Reference in New Issue
Block a user