Skip to content

Commit

Permalink
feat: add ko-build tests
Browse files Browse the repository at this point in the history
test ko build functions
  • Loading branch information
BobyMCbobs committed Oct 2, 2023
1 parent ca62755 commit 587ebe5
Show file tree
Hide file tree
Showing 3 changed files with 165 additions and 3 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/reusable-ko-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ jobs:
go-version-file: go.mod
cache-dependency-path: go.sum
check-latest: true
- name: setup
run: |
eval '${{ inputs.setup }}'
- id: run-info
name: collect job run info
env:
Expand All @@ -109,9 +112,6 @@ jobs:
with:
version: ${{ env.VERSION_CRANE }}
- uses: GeoNet/setup-ko@190558b6b0e4ebe7e2caa5d99309563d1bceaa8d # main
- name: setup
run: |
eval '${{ inputs.setup }}'
- name: get session name
id: get-session-name
if: ${{ inputs.aws-region != '' && inputs.aws-role-arn-to-assume != '' && inputs.aws-role-duration-seconds != '' && inputs.registryOverride != '' }}
Expand Down
159 changes: 159 additions & 0 deletions .github/workflows/test-reusable-ko-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
name: test reusable-ko-build
on:
pull_request: {}
workflow_dispatch: {}
env:
VERSION_CRANE: v0.16.1

# LIMITATIONS
# - this workflow cannot run in parallel between PRs; retries are required (for now).
# this is due to non-unique image names. having unique image names tends to cause needing to retry more times due to some sort of internal container artifact "registration" behaviour

# TESTCASES
# - t0: basic
# - t1: auth-with-geonetci
# - t2: with-paths-and-packages
# - t3: no-push

permissions:
packages: write
contents: read
id-token: write
jobs:
t0-basic:
uses: ./.github/workflows/reusable-ko-build.yml
with:
push: true
setup: |
mkdir -p testdata-ko-build/cmd/testimage-ko-build-t0-basic-1
cat << EOF > testdata-ko-build/cmd/testimage-ko-build-t0-basic-1/main.go
package main
import "fmt"
func main() {
fmt.Println("Hello World!")
}
EOF
t0-basic-check:
needs: t0-basic
runs-on: ubuntu-latest
steps:
- uses: GeoNet/setup-crane@00c9e93efa4e1138c9a7a5c594acd6c75a2fbf0c # main
with:
version: ${{ env.VERSION_CRANE }}
- name: check for images
env:
IMAGES: ${{ needs.t0-basic.outputs.images }}
run: |
echo "$IMAGES" | tr ',' '\n' | xargs -n 1 -I{} crane manifest {}
- name: cleanup
if: always()
env:
GH_TOKEN: ${{ github.token }}
run: |
gh api -X DELETE /orgs/GeoNet/packages/container/actions%2Ftestimage-ko-build-t0-basic-1 || true
t1-auth-with-geonetci:
uses: ./.github/workflows/reusable-ko-build.yml
secrets: inherit
with:
push: true
registryGhcrUsernameOverride: geonetci
setup: |
mkdir -p testdata-ko-build/cmd/testimage-ko-build-t1-auth-with-geonetci-1
cat << EOF > testdata-ko-build/cmd/testimage-ko-build-t1-auth-with-geonetci-1/main.go
package main
import "fmt"
func main() {
fmt.Println("Hello World!")
}
EOF
t1-auth-with-geonetci-check:
needs: t1-auth-with-geonetci
runs-on: ubuntu-latest
steps:
- uses: GeoNet/setup-crane@00c9e93efa4e1138c9a7a5c594acd6c75a2fbf0c # main
with:
version: ${{ env.VERSION_CRANE }}
- name: check for images
env:
IMAGES: ${{ needs.t1-auth-with-geonetci.outputs.images }}
run: |
echo "$IMAGES" | tr ',' '\n' | xargs -n 1 -I{} crane manifest {}
- name: cleanup
if: always()
env:
GH_TOKEN: ${{ github.token }}
run: |
gh api -X DELETE /orgs/GeoNet/packages/container/actions%2Ftestimage-ko-build-t1-auth-with-geonetci-1 || true
t2-with-paths-and-packages:
uses: ./.github/workflows/reusable-ko-build.yml
with:
push: true
paths: |
./testdata-ko-build/cmd/testimage-ko-build-t2-with-paths-and-packages-1
github.com/GeoNet/Actions/testdata-ko-build/cmd/testimage-ko-build-t2-with-paths-and-packages-2
setup: |
mkdir -p testdata-ko-build/cmd/testimage-ko-build-t2-with-paths-and-packages-1
cat << EOF > testdata-ko-build/cmd/testimage-ko-build-t2-with-paths-and-packages-1/main.go
package main
import "fmt"
func main() {
fmt.Println("Hello World!")
}
EOF
mkdir -p testdata-ko-build/cmd/testimage-ko-build-t2-with-paths-and-packages-2
cat << EOF > testdata-ko-build/cmd/testimage-ko-build-t2-with-paths-and-packages-2/main.go
package main
import "fmt"
func main() {
fmt.Println("Hello World!")
}
EOF
t2-with-paths-and-packages-check:
needs: t2-with-paths-and-packages
runs-on: ubuntu-latest
steps:
- uses: GeoNet/setup-crane@00c9e93efa4e1138c9a7a5c594acd6c75a2fbf0c # main
with:
version: ${{ env.VERSION_CRANE }}
- name: check for images
env:
IMAGES: ${{ needs.t2-with-paths-and-packages.outputs.images }}
run: |
echo "$IMAGES" | tr ',' '\n' | sort | cut -d'@' -f1 | xargs | grep -qE '^ghcr.io/geonet/actions/testimage-ko-build-t2-with-paths-and-packages-1 ghcr.io/geonet/actions/testimage-ko-build-t2-with-paths-and-packages-2$'
echo "$IMAGES" | tr ',' '\n' | xargs -n 1 -I{} crane manifest {}
- name: cleanup
if: always()
env:
GH_TOKEN: ${{ github.token }}
run: |
gh api -X DELETE /orgs/GeoNet/packages/container/actions%2Ftestimage-ko-build-t2-with-paths-and-packages-1 || true
gh api -X DELETE /orgs/GeoNet/packages/container/actions%2Ftestimage-ko-build-t2-with-paths-and-packages-2 || true
t3-no-push:
uses: ./.github/workflows/reusable-ko-build.yml
with:
push: false
setup: |
mkdir -p testdata-ko-build/cmd/testimage-ko-build-t3-no-push-1
cat << EOF > testdata-ko-build/cmd/testimage-ko-build-t3-no-push-1/main.go
package main
import "fmt"
func main() {
fmt.Println("Hello World!")
}
EOF
t3-no-push-check:
needs: t3-no-push
runs-on: ubuntu-latest
steps:
- uses: GeoNet/setup-crane@00c9e93efa4e1138c9a7a5c594acd6c75a2fbf0c # main
with:
version: ${{ env.VERSION_CRANE }}
- name: check for images
env:
IMAGE: ${{ needs.t3-no-push.outputs.images }}
GH_TOKEN: ${{ github.token }}
run: |
! crane manifest $IMAGE || \
(
gh api -X DELETE /orgs/GeoNet/packages/container/actions%2Ftestimage-ko-build-t3-no-push-1 || true
)
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module github.com/GeoNet/Actions

go 1.20

0 comments on commit 587ebe5

Please sign in to comment.