Skip to content

Commit fd71e50

Browse files
authored
Replace repository_dispatch with a watcher workflow for creating releases. (#34)
Signed-off-by: Derek Nola <derek.nola@suse.com>
1 parent c2f3a16 commit fd71e50

2 files changed

Lines changed: 107 additions & 33 deletions

File tree

.github/workflows/create-tag-on-dispatch.yml

Lines changed: 0 additions & 33 deletions
This file was deleted.
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
name: Watch K3s Releases
2+
3+
on:
4+
schedule:
5+
# Check for new releases every 2 hours
6+
- cron: '0 */2 * * *'
7+
workflow_dispatch:
8+
9+
permissions:
10+
contents: write
11+
id-token: write
12+
13+
jobs:
14+
check-new-release:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Checkout code
18+
uses: actions/checkout@v4
19+
with:
20+
fetch-depth: 0 # Fetch all history to get all tags
21+
22+
- name: Process K3s releases
23+
id: process-releases
24+
env:
25+
GH_TOKEN: ${{ github.token }}
26+
run: |
27+
# Get the last 50 K3s releases
28+
RELEASES=$(curl -sL https://api.github.com/repos/k3s-io/k3s/releases | jq -r '[.[] | select(.assets[] | length > 2) | .tag_name] | unique | .[0:50][]')
29+
30+
echo "Processing last 50 K3s releases:"
31+
32+
RELEASES_TO_CREATE=()
33+
34+
for K3S_VERSION in $RELEASES; do
35+
echo ""
36+
echo "Checking K3s release: $K3S_VERSION"
37+
38+
# Check if we already have a tag for this version
39+
if git rev-parse "$K3S_VERSION" >/dev/null 2>&1; then
40+
echo " Tag $K3S_VERSION already exists, skipping"
41+
continue
42+
fi
43+
44+
echo " Tag $K3S_VERSION does not exist, checking binaries"
45+
46+
# Check for required binaries
47+
ASSETS=$(curl -sL "https://api.github.com/repos/k3s-io/k3s/releases/tags/$K3S_VERSION" | jq -r '.assets[].name')
48+
REQUIRED_BINARIES=("k3s" "k3s-arm64" "k3s-armhf")
49+
MISSING_BINARIES=()
50+
51+
for binary in "${REQUIRED_BINARIES[@]}"; do
52+
if ! echo "$ASSETS" | grep -q "^${binary}$"; then
53+
MISSING_BINARIES+=("$binary")
54+
fi
55+
done
56+
57+
if [ ${#MISSING_BINARIES[@]} -gt 0 ]; then
58+
echo " Release $K3S_VERSION is missing required binaries: ${MISSING_BINARIES[*]}"
59+
echo " Skipping release creation until all binaries are published"
60+
else
61+
echo " All required binaries present for $K3S_VERSION"
62+
RELEASES_TO_CREATE+=("$K3S_VERSION")
63+
fi
64+
done
65+
66+
if [ ${#RELEASES_TO_CREATE[@]} -gt 0 ]; then
67+
echo "releases_to_create=$(printf '%s\n' "${RELEASES_TO_CREATE[@]}" | tr '\n' ' ' | sed 's/ $//')" >> $GITHUB_OUTPUT
68+
echo "has_releases=true" >> $GITHUB_OUTPUT
69+
else
70+
echo "has_releases=false" >> $GITHUB_OUTPUT
71+
echo ""
72+
echo "No new releases to create"
73+
fi
74+
75+
- name: Read Vault secrets
76+
if: steps.process-releases.outputs.has_releases == 'true'
77+
uses: rancher-eio/read-vault-secrets@main
78+
with:
79+
secrets: |
80+
secret/data/github/repo/${{ github.repository }}/github/app-credentials appId | APP_ID ;
81+
secret/data/github/repo/${{ github.repository }}/github/app-credentials privateKey | PRIVATE_KEY ;
82+
83+
- name: Generate short-lived github app token
84+
if: steps.process-releases.outputs.has_releases == 'true'
85+
uses: actions/create-github-app-token@v1
86+
id: app-token
87+
with:
88+
app-id: ${{ env.APP_ID }}
89+
private-key: ${{ env.PRIVATE_KEY }}
90+
91+
- name: Create Releases
92+
if: steps.process-releases.outputs.has_releases == 'true'
93+
env:
94+
GH_TOKEN: ${{ steps.app-token.outputs.token }}
95+
run: |
96+
echo "Creating releases for the following K3s versions:"
97+
echo "${{ steps.process-releases.outputs.releases_to_create }}"
98+
echo ""
99+
100+
for K3S_VERSION in ${{ steps.process-releases.outputs.releases_to_create }}; do
101+
echo "Creating release for $K3S_VERSION"
102+
gh release create "$K3S_VERSION" \
103+
--title "Release $K3S_VERSION" \
104+
--notes "Automated release for K3s $K3S_VERSION"
105+
echo "Successfully created release $K3S_VERSION"
106+
echo ""
107+
done

0 commit comments

Comments
 (0)