ci: replace setup-go with custom action to avoid cache error and test pre-release go

This commit is contained in:
Li Jie
2025-02-13 19:14:44 +08:00
parent 058f74c12c
commit 70fb5ec7e1
5 changed files with 67 additions and 16 deletions

51
.github/actions/setup-go/action.yml vendored Normal file
View File

@@ -0,0 +1,51 @@
name: "Setup Go"
description: "Setup Go environment by downloading and extracting from go.dev"
inputs:
go-version:
description: "The Go version to download and use"
required: true
runs:
using: "composite"
steps:
- name: Download and setup Go
shell: bash
run: |
set -e
GO_VERSION="${{ inputs.go-version }}"
GO_VERSION="${GO_VERSION#go}" # Remove 'go' prefix if present
# Determine OS and architecture
if [[ "$RUNNER_OS" == "macOS" ]]; then
OS="darwin"
ARCH="arm64"
else
OS="linux"
ARCH="amd64"
fi
DOWNLOAD_URL="https://go.dev/dl/go${GO_VERSION}.${OS}-${ARCH}.tar.gz"
echo "Downloading Go from: ${DOWNLOAD_URL}"
# Create temporary directory for download
TMP_DIR=$(mktemp -d)
curl -L "${DOWNLOAD_URL}" -o "${TMP_DIR}/go.tar.gz"
# Remove existing Go installation if any
sudo rm -rf /usr/local/go
# Extract to /usr/local
sudo tar -C /usr/local -xzf "${TMP_DIR}/go.tar.gz"
# Clean up
rm -rf "${TMP_DIR}"
# Add to PATH
echo "/usr/local/go/bin" >> $GITHUB_PATH
echo "$HOME/go/bin" >> $GITHUB_PATH
- name: Verify Go installation
shell: bash
run: |
# Verify installation
echo "Verifying Go installation..."
go version

View File

@@ -40,9 +40,9 @@ jobs:
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
uses: ./.github/actions/setup-go
with:
go-version: '1.23'
go-version: '1.23.6'
- name: Install dependencies on macOS
if: startsWith(matrix.os, 'macos')

View File

@@ -13,9 +13,9 @@ jobs:
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
uses: ./.github/actions/setup-go
with:
go-version: '1.23'
go-version: '1.23.6'
- name: Check formatting
run: |

View File

@@ -35,9 +35,9 @@ jobs:
clang --version
- name: Set up Go
uses: actions/setup-go@v5
uses: ./.github/actions/setup-go
with:
go-version: '1.23'
go-version: '1.23.6'
- name: Build
run: go build -v ./...

View File

@@ -17,7 +17,7 @@ jobs:
- macos-latest
- ubuntu-24.04
llvm: [18]
go: ['1.20', '1.21', '1.22', '1.23']
go: ['1.20.14', '1.21.13', '1.22.12', '1.23.6']
runs-on: ${{matrix.os}}
steps:
- uses: actions/checkout@v4
@@ -35,9 +35,9 @@ jobs:
pip3.12 install --break-system-packages "${py_deps[@]}"
- name: Set up Go for build
uses: actions/setup-go@v5
uses: ./.github/actions/setup-go
with:
go-version: '1.23'
go-version: '1.23.6'
- name: Install
working-directory: compiler
@@ -98,7 +98,7 @@ jobs:
matrix:
os: [ubuntu-24.04, macos-latest]
llvm: [18]
go: ['1.20', '1.21', '1.22', '1.23']
go: ['1.20.14', '1.21.13', '1.22.12', '1.23.6']
runs-on: ${{matrix.os}}
steps:
- uses: actions/checkout@v4
@@ -108,9 +108,9 @@ jobs:
llvm-version: ${{matrix.llvm}}
- name: Set up Go 1.23 for building llgo
uses: actions/setup-go@v5
uses: ./.github/actions/setup-go
with:
go-version: '1.23'
go-version: '1.23.6'
- name: Install llgo
working-directory: compiler
@@ -119,26 +119,26 @@ jobs:
echo "LLGO_ROOT=$GITHUB_WORKSPACE" >> $GITHUB_ENV
- name: Set up Go for testing
uses: actions/setup-go@v5
uses: ./.github/actions/setup-go
with:
go-version: ${{matrix.go}}
- name: Test Hello World with go.mod 1.20
if: matrix.go == '1.20' || matrix.go == '1.21' || matrix.go == '1.22' || matrix.go == '1.23'
if: startsWith(matrix.go, '1.20') || startsWith(matrix.go, '1.21') || startsWith(matrix.go, '1.22') || startsWith(matrix.go, '1.23')
uses: ./.github/actions/test-helloworld
with:
go-version: ${{matrix.go}}
mod-version: '1.20'
- name: Test Hello World with go.mod 1.21
if: matrix.go == '1.21' || matrix.go == '1.22' || matrix.go == '1.23'
if: startsWith(matrix.go, '1.21') || startsWith(matrix.go, '1.22') || startsWith(matrix.go, '1.23')
uses: ./.github/actions/test-helloworld
with:
go-version: ${{matrix.go}}
mod-version: '1.21'
- name: Test Hello World with go.mod 1.22
if: matrix.go == '1.22' || matrix.go == '1.23'
if: startsWith(matrix.go, '1.22') || startsWith(matrix.go, '1.23')
uses: ./.github/actions/test-helloworld
with:
go-version: ${{matrix.go}}