Skip to content

Commit 59a042f

Browse files
chore(ci): add GitHub Actions workflow for platform-specific release artifacts
1 parent 9dd8080 commit 59a042f

File tree

1 file changed

+170
-0
lines changed

1 file changed

+170
-0
lines changed

.github/workflows/release.yml

Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
name: Create Platform-Specific Artifacts
2+
3+
permissions:
4+
contents: write
5+
packages: read
6+
7+
on:
8+
release:
9+
types: [ published ]
10+
11+
workflow_dispatch:
12+
inputs:
13+
release_tag:
14+
description: 'Release tag to build artifacts for'
15+
required: false
16+
type: string
17+
18+
jobs:
19+
prepare-artifacts:
20+
runs-on: ubuntu-latest
21+
22+
outputs:
23+
platforms: ${{ steps.generate-matrix.outputs.platforms }}
24+
25+
steps:
26+
- name: Checkout code
27+
uses: actions/checkout@v4
28+
with:
29+
ref: ${{ github.event.inputs.release_tag || github.ref }}
30+
31+
- name: Install yq
32+
run: |
33+
wget https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64 -O /usr/local/bin/yq
34+
chmod +x /usr/local/bin/yq
35+
36+
- name: Generate Build Matrix
37+
id: generate-matrix
38+
run: |
39+
# Extract platforms from platforms.yml
40+
platforms=$(yq -o=json 'keys' platforms.yml)
41+
echo "platforms=$(echo $platforms | jq -c '. | map(split("/")[0]) | unique')" >> $GITHUB_OUTPUT
42+
43+
build-artifacts:
44+
needs: prepare-artifacts
45+
46+
runs-on: ubuntu-latest
47+
48+
strategy:
49+
matrix:
50+
platform: ${{ fromJson(needs.prepare-artifacts.outputs.platforms) }}
51+
52+
steps:
53+
- name: Checkout code
54+
uses: actions/checkout@v4
55+
with:
56+
ref: ${{ github.event.inputs.release_tag || github.ref }}
57+
58+
- name: Install yq
59+
run: |
60+
wget https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64 -O /usr/local/bin/yq
61+
chmod +x /usr/local/bin/yq
62+
63+
- name: Create Platform-Specific Artifact
64+
run: |
65+
# Prepare exclusion list
66+
if [ -f ".gitignore" ]; then
67+
cp .gitignore rsync_exclude.txt
68+
else
69+
touch rsync_exclude.txt
70+
fi
71+
72+
# Add platform-specific exclusions from platforms.yml
73+
echo "" >> rsync_exclude.txt
74+
yq e ".\"${{ matrix.platform }}\".exclude[]" platforms.yml >> rsync_exclude.txt
75+
76+
# Add standard exclusions
77+
echo ".git" >> rsync_exclude.txt
78+
echo ".github" >> rsync_exclude.txt
79+
echo "rsync_exclude.txt" >> rsync_exclude.txt
80+
81+
# Copy files using rsync with exclusions
82+
DIST_DIR="dist-${{ matrix.platform }}"
83+
mkdir -p "$DIST_DIR"
84+
echo "$DIST_DIR" >> rsync_exclude.txt
85+
rsync -av --exclude-from=rsync_exclude.txt ./ "$DIST_DIR"/
86+
87+
# Compress artifact
88+
if [[ "${{ matrix.platform }}" == windows-* ]]; then
89+
zip -r "dist-${{ matrix.platform }}.zip" "$DIST_DIR"
90+
ARTIFACT_EXT="zip"
91+
else
92+
tar -czvf "dist-${{ matrix.platform }}.tar.gz" "$DIST_DIR"
93+
ARTIFACT_EXT="tar.gz"
94+
fi
95+
96+
echo "Artifact created: dist-${{ matrix.platform }}.$ARTIFACT_EXT"
97+
98+
- name: Upload Artifact to Release
99+
uses: softprops/action-gh-release@v2
100+
if: startsWith(github.ref, 'refs/tags/')
101+
with:
102+
files: dist-*
103+
104+
- name: Upload Artifact to Artifact Hub
105+
uses: actions/upload-artifact@v4
106+
with:
107+
name: dist-${{ matrix.platform }}
108+
path: dist-*
109+
retention-days: 1
110+
111+
create-release-metadata:
112+
needs: [ prepare-artifacts, build-artifacts ]
113+
114+
runs-on: ubuntu-latest
115+
116+
steps:
117+
- name: Checkout code
118+
uses: actions/checkout@v4
119+
with:
120+
ref: ${{ github.event.inputs.release_tag || github.ref }}
121+
122+
- name: Install yq
123+
run: |
124+
wget https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64 -O /usr/local/bin/yq
125+
chmod +x /usr/local/bin/yq
126+
127+
- name: Generate Platform URLs Metadata
128+
run: |
129+
# Prepare variables
130+
RELEASE_TAG="${{ github.event.inputs.release_tag || github.ref }}"
131+
REPO="${{ github.repository }}"
132+
133+
# Start JSON structure
134+
echo "{" > platform-urls.json
135+
echo ' "platform-urls": {' >> platform-urls.json
136+
137+
# Generate URLs for each platform
138+
FIRST=true
139+
platforms=$(yq -o=json 'keys' platforms.yml | jq -r '.[]')
140+
for platform in $platforms; do
141+
if [ "$FIRST" = true ]; then
142+
FIRST=false
143+
else
144+
echo "," >> platform-urls.json
145+
fi
146+
147+
# Determine file extension
148+
if [[ "$platform" == windows-* ]]; then
149+
EXT="zip"
150+
else
151+
EXT="tar.gz"
152+
fi
153+
154+
# Generate URL
155+
printf ' "%s": "https://github.com/%s/releases/download/%s/dist-%s.%s"' \
156+
"$platform" "$REPO" "$RELEASE_TAG" "$platform" "$EXT" >> platform-urls.json
157+
done
158+
159+
# Close JSON structure
160+
echo "" >> platform-urls.json
161+
echo ' }' >> platform-urls.json
162+
echo "}" >> platform-urls.json
163+
164+
cat platform-urls.json
165+
166+
- name: Upload Platform URLs Metadata
167+
uses: softprops/action-gh-release@v2
168+
if: startsWith(github.ref, 'refs/tags/')
169+
with:
170+
files: platform-urls.json

0 commit comments

Comments
 (0)