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-region: description: S3 region name. default: us-east-1 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 custom Cloudflare-compatible go-cache-plugin..." cd "${{ github.action_path }}/../../../go-cache-plugin-src" go build -o $HOME/go/bin/go-cache-plugin ./cmd/go-cache-plugin - 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 with verbose debug logging and metrics CMD="$HOME/go/bin/go-cache-plugin -v --metrics --debug=1 --cache-dir=$CACHE_DIR --bucket=${{ inputs.s3-bucket }} --region=${{ inputs.s3-region }}" 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 ONLY for Go 1.21-1.23 compatibility GO_VER=$(go env GOVERSION | grep -oE '[0-9]+\.[0-9]+' | head -n 1) echo "Detected Go version: $GO_VER" if [ "$GO_VER" = "1.21" ] || [ "$GO_VER" = "1.22" ] || [ "$GO_VER" = "1.23" ]; then echo "Enabling GOEXPERIMENT=cacheprog for compatibility" echo "GOEXPERIMENT=cacheprog" >> "$GITHUB_ENV" else echo "GOEXPERIMENT=cacheprog is not needed or supported in Go 1.24+" fi # Diagnose secret population echo "Diagnosing secrets..." echo "SCCACHE_AWS_ACCESS_KEY_ID length: ${#SCCACHE_AWS_ACCESS_KEY_ID}" echo "SCCACHE_AWS_SECRET_ACCESS_KEY length: ${#SCCACHE_AWS_SECRET_ACCESS_KEY}" # 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