Skip to content

Commit 4b2e740

Browse files
committed
build and release images seperate from plugin
Signed-off-by: James Sturtevant <jsturtevant@gmail.com>
1 parent a55bb74 commit 4b2e740

4 files changed

Lines changed: 109 additions & 41 deletions

File tree

.github/workflows/cleanup.yaml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: image-cleanup
2+
3+
on:
4+
schedule:
5+
- cron: '4 */23 * * *'
6+
workflow_dispatch:
7+
8+
permissions:
9+
contents: read
10+
packages: write
11+
12+
jobs:
13+
# use gh cli to delete container images from registry when it is pr event
14+
clean-up-pr-images:
15+
runs-on: ubuntu-latest
16+
steps:
17+
# delete images
18+
- name: delete images
19+
env:
20+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
21+
run: |
22+
echo "deleting images that start with 'pr-'"
23+
images=$(gh api \
24+
-H "Accept: application/vnd.github+json" \
25+
/users/jsturtevant/packages/container/debug-installer/versions \
26+
--jq '.[] | select(.metadata.container.tags | any(startswith("pr-"))) | .id')
27+
28+
for image in $images; do
29+
# check if image is older than 20hrs
30+
image_age=$(gh api \
31+
-H "Accept: application/vnd.github+json" \
32+
/users/jsturtevant/packages/container/debug-installer/versions/$image \
33+
--jq '.updated_at')
34+
35+
if [[ $(date -d "$image_age" +%s) > $(date -d "24 hours ago" +%s) ]]; then
36+
echo "image $image isn't old enough, skipping"
37+
continue
38+
fi
39+
40+
echo "deleting image $image"
41+
# https://github.com/cli/cli/issues/3937
42+
echo -n | gh api --method DELETE -H "Accept: application/vnd.github+json" /users/jsturtevant/packages/container/debug-installer/versions/$image --input -
43+
done

.github/workflows/installer.yaml

Lines changed: 64 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
name: installer-image
1+
name: image
22

33
on:
44
push:
5-
tags: ["installer-v*"]
5+
tags: ["image-v*"]
66
branches:
77
- main
88
pull_request:
99
branches:
1010
- main
1111

1212
permissions:
13-
contents: read
1413
packages: write
14+
pull-requests: write
1515

1616
jobs:
1717
build-installer-image:
@@ -24,11 +24,69 @@ jobs:
2424
username: ${{ github.repository_owner }}
2525
password: ${{ secrets.GITHUB_TOKEN }}
2626
- uses: actions/checkout@v2
27+
# set image version based on event type
28+
- name: get version from tag
29+
if: ${{ github.event_name != 'pull_request' && github.ref_type == 'tag' }}
30+
run: |
31+
$imageversion=$env:GITHUB_REF_NAME -replace "image-", ""
32+
"IMAGE_VERSION=$imageversion" >> $env:GITHUB_ENV
33+
- name: get version for PR
34+
if: ${{ github.event_name == 'pull_request' }}
35+
run: |
36+
"IMAGE_VERSION=pr-${{ github.event.number }}" >> $env:GITHUB_ENV
37+
# build and publish image
38+
# need to always publish this image so can use it to build the debug image for verification
2739
- name: build image
2840
run: |
29-
.\build-installer.ps1 -version $env:GITHUB_REF_NAME
41+
echo $env:IMAGE_VERSION
42+
.\build-installer.ps1 -version $env:IMAGE_VERSION
3043
- name: push image
31-
if: ${{ github.event_name != 'pull_request' && github.ref_type == 'tag' }}
3244
run: |
33-
$tag=$env:GITHUB_REF_NAME
45+
echo $env:IMAGE_VERSION
46+
$tag=$env:IMAGE_VERSION
3447
docker image push ghcr.io/jsturtevant/debug-installer:$tag
48+
- name: comment on PR
49+
if: ${{ github.event_name == 'pull_request' }}
50+
env:
51+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
52+
run: |
53+
$comment=@"
54+
Thank you for the contribution :rocket: The debug installer cache image has been published to a temporary repository.
55+
56+
You can use it by referencing: ``ghcr.io/jsturtevant/debug-installer:$env:IMAGE_VERSION``.
57+
58+
It will be removed in 24 hours.
59+
"@
60+
61+
gh api --method POST -H "Accept: application/vnd.github+json" /repos/jsturtevant/windows-debug/issues/${{ github.event.pull_request.number }}/comments -f body="$comment"
62+
build-debug-image:
63+
needs: build-installer-image
64+
runs-on: ubuntu-latest
65+
steps:
66+
- name: login to GitHub container registry
67+
uses: docker/login-action@v1
68+
with:
69+
registry: ghcr.io
70+
username: ${{ github.repository_owner }}
71+
password: ${{ secrets.GITHUB_TOKEN }}
72+
- uses: actions/checkout@v2
73+
# set image version based on event type
74+
- name: get version from tag
75+
if: ${{ github.event_name != 'pull_request' && github.ref_type == 'tag' }}
76+
run: |
77+
imageversion=echo $GITHUB_REF_NAME | sed 's/^image-//'
78+
echo "IMAGE_VERSION=$imageversion" >> $GITHUB_ENV
79+
- name: get version for PR
80+
if: ${{ github.event_name == 'pull_request' }}
81+
run: |
82+
echo "IMAGE_VERSION=pr-${{ github.event.number }}" >> $GITHUB_ENV
83+
# build and publish image
84+
- name: build image
85+
run: |
86+
echo $IMAGE_VERSION
87+
sudo VERSION=$IMAGE_VERSION INSTALLER_VERSION=$IMAGE_VERSION ./build.sh
88+
- name: push image
89+
if: ${{ github.event_name != 'pull_request' && github.ref_type == 'tag' }}
90+
run: |
91+
echo $IMAGE_VERSION
92+
OUTPUT=registry VERSION=$IMAGE_VERSION INSTALLER_VERSION=$IMAGE_VERSION ./build.sh

.github/workflows/release.yaml

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,7 @@ on:
1111
- main
1212

1313
jobs:
14-
build-debug-image:
15-
runs-on: ubuntu-latest
16-
steps:
17-
- name: login to GitHub container registry
18-
uses: docker/login-action@v1
19-
with:
20-
registry: ghcr.io
21-
username: ${{ github.repository_owner }}
22-
password: ${{ secrets.GITHUB_TOKEN }}
23-
- uses: actions/checkout@v2
24-
- name: build image
25-
run: |
26-
sudo VERSION=$GITHUB_REF_NAME ./build.sh
27-
- name: push image
28-
if: ${{ github.event_name != 'pull_request' && github.ref_type == 'tag' }}
29-
run: |
30-
OUTPUT=registry VERSION=$GITHUB_REF_NAME ./build.sh
3114
release:
32-
needs: build-debug-image
3315
runs-on: ubuntu-latest
3416
if: ${{ github.event_name != 'pull_request' && github.ref_type == 'tag' }}
3517
steps:
@@ -42,5 +24,5 @@ jobs:
4224
uses: softprops/action-gh-release@v1
4325
with:
4426
files: kubectl-windows-debug-${{ github.ref_name }}.tar.gz
45-
# - name: Update new version in krew-index
46-
# uses: rajatjindal/krew-release-bot@v0.0.43
27+
- name: Update new version in krew-index
28+
uses: rajatjindal/krew-release-bot@v0.0.43

.goreleaser.yaml

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)