Skip to content

Commit 13cf6da

Browse files
committed
github: Add workflow to draft plugin releases
Signed-off-by: Evangelos Skopelitis <[email protected]>
1 parent b096ca6 commit 13cf6da

File tree

1 file changed

+100
-0
lines changed

1 file changed

+100
-0
lines changed
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
name: Create plugin release draft
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
plugin:
7+
description: 'The plugin name (e.g., flux)'
8+
required: true
9+
type: string
10+
version:
11+
description: 'The plugin version (e.g., 0.1.0)'
12+
required: true
13+
type: string
14+
15+
env:
16+
REGISTRY: ghcr.io
17+
jobs:
18+
release:
19+
runs-on: ubuntu-latest
20+
steps:
21+
- name: Checkout cpde
22+
uses: actions/checkout@v3
23+
24+
- name: Setup Node.js
25+
uses: actions/setup-node@v3
26+
with:
27+
node-version: '20'
28+
29+
- name: Setup Docker Buildx
30+
uses: docker/setup-buildx-action@988b5a0280414f521da01fcc63a27aeeb4b104db # v3.6.1
31+
32+
- name: Log in to the Container registry
33+
uses: docker/login-action@465a07811f14bebb1938fbed4728c6a1ff8901fc # v2.2.0
34+
with:
35+
registry: ${{ env.REGISTRY }}
36+
username: ${{ github.actor }}
37+
password: ${{ github.token }}
38+
39+
- name: Build plugin tarball
40+
id: build_tarball
41+
run: |
42+
PLUGIN="${{ github.event.inputs.plugin }}"
43+
cd $PLUGIN
44+
npm install
45+
npm run build
46+
OUTPUT=$(npx @kinvolk/headlamp-plugin package | tail -n2)
47+
TARBALL=$(echo "$OUTPUT" | head -n1 | sed -E 's/Created tarball: "([^"]+)".*/\1/')
48+
CHECKSUM=$(echo "$OUTPUT" | tail -n1 | sed -E 's/Tarball checksum \(sha256\): (.*)/\1/')
49+
echo "tarball_path=$TARBALL" >> $GITHUB_ENV
50+
echo "checksum=$CHECKSUM" >> $GITHUB_ENV
51+
52+
- name: Check ArtifactHub pkg for in-cluster compatibility
53+
id: check_artifacthub
54+
run: |
55+
if grep -q "in-cluster" "${{ github.event.inputs.plugin }}/artifacthub-pkg.yml"; then
56+
echo "::set-output name=incluster::true"
57+
else
58+
echo "::set-output name=incluster::false"
59+
fi
60+
61+
- name: Build and push OCI image
62+
if: steps.check_artifacthub.outputs.incluster == 'true'
63+
env:
64+
PLUGIN: ${{ github.event.inputs.plugin }}
65+
VERSION: ${{ github.event.inputs.version }}
66+
REGISTRY: ${{ env.REGISTRY }}
67+
IMAGE_NAME: headlamp-plugin-${{ github.event.inputs.plugin }}
68+
run: |
69+
docker buildx build \
70+
--build-arg PLUGIN=$PLUGIN \
71+
-t $REGISTRY/headlamp-k8s/headlamp-plugin-$PLUGIN:$VERSION \
72+
--push \
73+
.
74+
75+
- name: Create release draft and push tarball
76+
uses: softprops/action-gh-release@de2c0eb89ae2a093876385947365aca7b0e5f844 # v1
77+
with:
78+
draft: true
79+
token: ${{ secrets.GITHUB_TOKEN }}
80+
name: "${{ github.event.inputs.plugin }} ${{ github.event.inputs.version }}"
81+
body: Draft release for ${{ github.event.inputs.plugin }} version ${{ github.event.inputs.version }}
82+
files: ${{ steps.build_tarball.outputs.tarball_path }}
83+
env:
84+
GITHUB_TOKEN: ${{ github.repository }}
85+
86+
- name: Update ArtifactHub pkg file
87+
env:
88+
PLUGIN: ${{ github.event.inputs.plugin }}
89+
VERSION: ${{ github.event.inputs.version }}
90+
TAR_PATH: ${{ steps.build_tarball.outputs.tarball_path }}
91+
CHECKSUM: ${{ steps.build_tarball.outputs.checksum }}
92+
run: |
93+
PKG_FILE="${PLUGIN}/artifacthub-pkg.yml"
94+
TAR_URL="https://github.com/headlamp-k8s/plugins/releases/download/${PLUGIN}-${VERSION}/$(basename $TAR_PATH)"
95+
sed -i "s|^\(headlamp/plugin/archive-url:\).*|\1 \"$TAR_URL\"|g" "$PKG_FILE"
96+
sed -i "s|^\(headlamp/plugin/archive-checksum:\).*|\1 \"SHA256:$CHECKSUM\"|g" "$PKG_FILE"
97+
98+
echo "ArtifactHub pkg file updated. Please review the changes below and commit manually:"
99+
git diff "$PKG_FILE"
100+

0 commit comments

Comments
 (0)