feat(actions): add go-cache composite action with S3 support

This commit is contained in:
2026-05-19 21:03:52 -07:00
commit 0ddbcd4222
2 changed files with 141 additions and 0 deletions

View File

@@ -0,0 +1,83 @@
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

58
README.md Normal file
View File

@@ -0,0 +1,58 @@
# actions-go
Reusable Gitea Actions for Go projects.
## actions/go-cache
Composite action that installs Go, installs `tailscale/go-cache-plugin`, and configures Go's native `GOCACHEPROG` to cache Go build and test artifacts in an S3-compatible backend.
This action avoids the need to tar/untar huge build directories manually and leverages standard S3 object storage for fast, reliable caching.
### S3 usage
Create an S3 bucket for your Go build cache, then pass S3 settings as inputs and credentials as normal workflow environment variables or secrets.
For ease of use and compatibility with `actions-rust`, the action automatically maps `SCCACHE_AWS_ACCESS_KEY_ID` and `SCCACHE_AWS_SECRET_ACCESS_KEY` to standard AWS environment variables if they are provided.
```yaml
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Go + S3 Caching
uses: https://git.ericxliu.me/eric/actions-go/.gitea/actions/go-cache@main
with:
go-version: '1.24'
s3-bucket: my-go-cache-bucket
s3-endpoint: https://s3.example.com
s3-path-style: "true"
env:
SCCACHE_AWS_ACCESS_KEY_ID: ${{ secrets.SCCACHE_AWS_ACCESS_KEY_ID }}
SCCACHE_AWS_SECRET_ACCESS_KEY: ${{ secrets.SCCACHE_AWS_SECRET_ACCESS_KEY }}
AWS_REGION: auto
- run: go test -v ./...
```
### Local usage
Omit `s3-bucket` to fall back to the default `setup-go` action's local caching behavior:
```yaml
- name: Setup Go (local cache)
uses: https://git.ericxliu.me/eric/actions-go/.gitea/actions/go-cache@main
with:
go-version: '1.24'
```
### Inputs
- `go-version`: Go version to install. Defaults to `stable`.
- `cache`: Set to `"false"` to opt-out of all caching setup.
- `go-cache-plugin-version`: Specific version tag or `latest` of the cache plugin. Defaults to `latest`.
- `s3-bucket`: S3 bucket name. Empty means local caching only.
- `s3-endpoint`: Optional S3-compatible endpoint URL (e.g., self-hosted MinIO or Ceph).
- `s3-path-style`: Set to `"true"` for endpoints requiring path-style addressing (e.g., MinIO).
- `cache-dir`: Local cache directory for caching. Defaults to `~/.cache/go-cache`.