Add .gitea/workflows/*.yaml
All checks were successful
Caching with Go / Cache Go (push) Successful in 42s

This commit is contained in:
2025-10-20 21:24:46 -07:00
parent 5d0059f7e3
commit 6b36f9058c
2 changed files with 76 additions and 50 deletions

View File

@@ -1,50 +1,50 @@
name: Cache Verify name: Cache Verify
on: on:
workflow_dispatch: workflow_dispatch:
jobs: jobs:
cache-verify: cache-verify:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v4 uses: actions/checkout@v4
# 1) Show what cache/runtimes URLs the runner injected into this job # 1) Show what cache/runtimes URLs the runner injected into this job
- name: Print cache environment - name: Print cache environment
run: | run: |
echo "ACTIONS_CACHE_URL=${ACTIONS_CACHE_URL}" echo "ACTIONS_CACHE_URL=${ACTIONS_CACHE_URL}"
echo "ACTIONS_RUNTIME_URL=${ACTIONS_RUNTIME_URL}" echo "ACTIONS_RUNTIME_URL=${ACTIONS_RUNTIME_URL}"
# 2) Ping the cache status endpoint (works with either host IP or service name) # 2) Ping the cache status endpoint (works with either host IP or service name)
- name: Probe cache server - name: Probe cache server
run: | run: |
URL="${ACTIONS_CACHE_URL%/}/_apis/artifactcache/status" URL="${ACTIONS_CACHE_URL%/}/_apis/artifactcache/status"
echo "Checking: $URL" echo "Checking: $URL"
if command -v curl >/dev/null 2>&1; then if command -v curl >/dev/null 2>&1; then
curl -fsS "$URL" curl -fsS "$URL"
else else
wget -qO- "$URL" wget -qO- "$URL"
fi fi
# 3) Use the cache action with a stable key # 3) Use the cache action with a stable key
# - First run => MISS (will SAVE at the end) # - First run => MISS (will SAVE at the end)
# - Second run => HIT # - Second run => HIT
- name: Use actions/cache - name: Use actions/cache
uses: actions/cache@v4 uses: actions/cache@v4
with: with:
path: ~/.cache/demo path: ~/.cache/demo
key: cache-verify-${{ runner.os }}-v1 key: cache-verify-${{ runner.os }}-v1
# 4) Write a marker file so we can see reuse across runs # 4) Write a marker file so we can see reuse across runs
- name: Write marker - name: Write marker
run: | run: |
mkdir -p ~/.cache/demo mkdir -p ~/.cache/demo
date -u +"%Y-%m-%dT%H:%M:%SZ" > ~/.cache/demo/when.txt date -u +"%Y-%m-%dT%H:%M:%SZ" > ~/.cache/demo/when.txt
echo "Wrote: $(cat ~/.cache/demo/when.txt)" echo "Wrote: $(cat ~/.cache/demo/when.txt)"
# 5) Read marker (on a cache HIT, this value will be from the previous run) # 5) Read marker (on a cache HIT, this value will be from the previous run)
- name: Read marker - name: Read marker
run: | run: |
echo "Marker content:" echo "Marker content:"
cat ~/.cache/demo/when.txt || echo "<missing>" cat ~/.cache/demo/when.txt || echo "<missing>"

View File

@@ -0,0 +1,26 @@
name: Caching with Go
on: push
jobs:
Cache-Go:
name: Cache Go
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: '>=1.20.1'
- uses: https://gitea.com/actions/go-hashfiles@v0.0.1
id: hash-go
with:
patterns: |
go.mod
go.sum
- name: cache go
id: cache-go
uses: actions/cache@v3
with: # Specify with your cache path
path: |
/your_cache_path
key: go_path-${{ steps.hash-go.outputs.hash }}
restore-keys: |-
go_cache-${{ steps.hash-go.outputs.hash }}