Update the CI workflow to handle both the legacy sources.list format and the new ubuntu.sources format when switching to Tsinghua mirrors
100 lines
2.8 KiB
YAML
100 lines
2.8 KiB
YAML
name: Build Backend
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- master
|
|
- dev
|
|
pull_request:
|
|
branches:
|
|
- master
|
|
- dev
|
|
|
|
env:
|
|
GO_VERSION: '1.26'
|
|
GOPROXY: https://goproxy.cn,direct
|
|
|
|
jobs:
|
|
build:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Set up Go
|
|
uses: actions/setup-go@v5
|
|
with:
|
|
go-version: ${{ env.GO_VERSION }}
|
|
cache: false
|
|
|
|
- name: Go cache info
|
|
run: |
|
|
echo "Go cache directory:"
|
|
go env GOCACHE
|
|
echo "Go module cache directory:"
|
|
go env GOMODCACHE
|
|
|
|
- name: Install build tools
|
|
run: |
|
|
if [ -f /etc/apt/sources.list.d/ubuntu.sources ]; then
|
|
sudo sed -i 's|http://archive.ubuntu.com/ubuntu|https://mirrors.tuna.tsinghua.edu.cn/ubuntu|g' /etc/apt/sources.list.d/ubuntu.sources
|
|
sudo sed -i 's|http://security.ubuntu.com/ubuntu|https://mirrors.tuna.tsinghua.edu.cn/ubuntu|g' /etc/apt/sources.list.d/ubuntu.sources
|
|
else
|
|
sudo sed -i 's|http://archive.ubuntu.com|https://mirrors.tuna.tsinghua.edu.cn|g' /etc/apt/sources.list
|
|
sudo sed -i 's|http://security.ubuntu.com|https://mirrors.tuna.tsinghua.edu.cn|g' /etc/apt/sources.list
|
|
fi
|
|
sudo apt-get update && sudo apt-get install -y gcc
|
|
|
|
- name: Download dependencies
|
|
run: go mod download
|
|
|
|
- name: Build
|
|
env:
|
|
GOOS: linux
|
|
GOARCH: amd64
|
|
CGO_ENABLED: 1
|
|
run: go build -v -o server ./cmd/server
|
|
|
|
- name: Upload artifacts
|
|
uses: actions/upload-artifact@v3
|
|
with:
|
|
name: backend-server-linux-amd64
|
|
path: server
|
|
|
|
build-docker:
|
|
runs-on: ubuntu-latest
|
|
needs: build
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v3
|
|
|
|
- name: Login to Gitea Container Registry
|
|
uses: docker/login-action@v3
|
|
with:
|
|
registry: code.littlelan.cn
|
|
username: ${{ secrets.GIT_USERNAME }}
|
|
password: ${{ secrets.GIT_TOKEN }}
|
|
|
|
- name: Download artifact
|
|
uses: actions/download-artifact@v3
|
|
with:
|
|
name: backend-server-linux-amd64
|
|
|
|
- name: Ensure binary executable
|
|
run: chmod +x ./server
|
|
|
|
- name: Build and push Docker image
|
|
uses: docker/build-push-action@v5
|
|
with:
|
|
context: .
|
|
push: true
|
|
tags: |
|
|
code.littlelan.cn/carrot_bbs/backend:latest
|
|
code.littlelan.cn/carrot_bbs/backend:${{ github.sha }}
|
|
platforms: linux/amd64
|
|
cache-from: type=registry,ref=code.littlelan.cn/carrot_bbs/backend:buildcache
|
|
cache-to: type=registry,ref=code.littlelan.cn/carrot_bbs/backend:buildcache,mode=max
|