84 lines
3.0 KiB
YAML
84 lines
3.0 KiB
YAML
name: Go Setup + S3 Caching
|
|
description: Install Go and configure tailscale/go-cache-plugin for Go builds with an S3-compatible backend in Gitea Actions
|
|
author: eric
|
|
|
|
inputs:
|
|
go-version:
|
|
description: Go version to install (e.g., 1.22, 1.24, stable)
|
|
default: stable
|
|
required: false
|
|
cache:
|
|
description: Enable S3 go-cache-plugin.
|
|
default: "true"
|
|
required: false
|
|
go-cache-plugin-version:
|
|
description: go-cache-plugin version tag or latest.
|
|
default: latest
|
|
required: false
|
|
s3-bucket:
|
|
description: S3 bucket for go cache. Leave empty to use local caching only.
|
|
default: ""
|
|
required: false
|
|
s3-endpoint:
|
|
description: Optional S3-compatible endpoint URL, for example https://s3.example.com.
|
|
default: ""
|
|
required: false
|
|
s3-path-style:
|
|
description: Enable path-style S3 addressing (useful for MinIO or custom Ceph setups).
|
|
default: "false"
|
|
required: false
|
|
cache-dir:
|
|
description: Local cache directory for go-cache-plugin before uploading/downloading from S3.
|
|
default: ~/.cache/go-cache
|
|
required: false
|
|
|
|
runs:
|
|
using: composite
|
|
steps:
|
|
- name: Setup Go
|
|
uses: https://gitea.com/actions/setup-go@v4
|
|
with:
|
|
go-version: ${{ inputs.go-version }}
|
|
# Disable default setup-go local cache if we are using our custom S3 caching
|
|
cache: ${{ inputs.s3-bucket == '' }}
|
|
|
|
- name: Install go-cache-plugin
|
|
if: ${{ inputs.cache == 'true' && inputs.s3-bucket != '' }}
|
|
shell: bash
|
|
run: |
|
|
echo "Installing go-cache-plugin..."
|
|
go install github.com/tailscale/go-cache-plugin/cmd/go-cache-plugin@${{ inputs.go-cache-plugin-version }}
|
|
|
|
- name: Configure Go Cache
|
|
if: ${{ inputs.cache == 'true' && inputs.s3-bucket != '' }}
|
|
shell: bash
|
|
run: |
|
|
# Expand cache-dir path
|
|
CACHE_DIR=$(eval echo "${{ inputs.cache-dir }}")
|
|
mkdir -p "$CACHE_DIR"
|
|
|
|
# Build GOCACHEPROG command
|
|
CMD="$HOME/go/bin/go-cache-plugin --cache-dir=$CACHE_DIR --bucket=${{ inputs.s3-bucket }}"
|
|
|
|
if [ -n "${{ inputs.s3-endpoint }}" ]; then
|
|
CMD="$CMD --s3-endpoint-url=${{ inputs.s3-endpoint }}"
|
|
fi
|
|
|
|
if [ "${{ inputs.s3-path-style }}" = "true" ]; then
|
|
CMD="$CMD --s3-path-style=true"
|
|
fi
|
|
|
|
echo "Configuring GOCACHEPROG: $CMD"
|
|
echo "GOCACHEPROG=$CMD" >> "$GITHUB_ENV"
|
|
|
|
# Ensure GOEXPERIMENT=cacheprog is enabled for Go 1.21-1.23 compatibility
|
|
echo "GOEXPERIMENT=cacheprog" >> "$GITHUB_ENV"
|
|
|
|
# Align with actions-rust: map SCCACHE secrets to standard AWS variables
|
|
if [ -n "$SCCACHE_AWS_ACCESS_KEY_ID" ] && [ -z "${AWS_ACCESS_KEY_ID:-}" ]; then
|
|
echo "AWS_ACCESS_KEY_ID=$SCCACHE_AWS_ACCESS_KEY_ID" >> "$GITHUB_ENV"
|
|
fi
|
|
if [ -n "$SCCACHE_AWS_SECRET_ACCESS_KEY" ] && [ -z "${AWS_SECRET_ACCESS_KEY:-}" ]; then
|
|
echo "AWS_SECRET_ACCESS_KEY=$SCCACHE_AWS_SECRET_ACCESS_KEY" >> "$GITHUB_ENV"
|
|
fi
|