Skip to content

Commit

Permalink
ci: 👷 add binaries build in ci/cd
Browse files Browse the repository at this point in the history
  • Loading branch information
this-is-tobi authored and titigmr committed Aug 3, 2024
1 parent 28c1dee commit 58d49fb
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 11 deletions.
20 changes: 13 additions & 7 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,14 @@ jobs:
short-sha: ${{ steps.infos.outputs.SHORT_SHA }}
platforms-json: ${{ steps.infos.outputs.PLATFORMS_JSON }}
steps:
- name: Checks-out repository
uses: actions/checkout@v4

- name: Get variables
id: infos
run: |
echo "SHORT_SHA=sha-$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
echo "PLATFORMS_JSON=$(echo "$PLATFORMS"| jq -c 'split(",")')" >> $GITHUB_OUTPUT
echo "PLATFORMS_JSON=$(echo '"${{ inputs.PLATFORMS }}"' | jq -c 'split(",")')" >> $GITHUB_OUTPUT
build-binaries:
name: Build application binaries
Expand All @@ -75,7 +78,7 @@ jobs:
- vars
strategy:
matrix:
platforms: ${{ needs.vars.outputs.platforms-json }}
platforms: ${{ fromJson(needs.vars.outputs.platforms-json) }}
steps:
- name: Checks-out repository
uses: actions/checkout@v4
Expand All @@ -93,17 +96,20 @@ jobs:

- name: Run build
run: |
BUILD_OS=$(echo ${{ matrix.platforms }} | cut -d '/' -f 1)
BUILD_ARCH=$(echo ${{ matrix.platforms }} | cut -d '/' -f 2,3)
export BUILD_OS="$(echo ${{ matrix.platforms }} | cut -d '/' -f 1)"
export BUILD_ARCH="$(echo ${{ matrix.platforms }} | cut -d '/' -f 2,3)"
echo "BUILD_OS=$BUILD_OS" >> $GITHUB_ENV
echo "BUILD_ARCH=$BUILD_ARCH" >> $GITHUB_ENV
CGO_ENABLED=0 GOOS=${BUILD_OS} GOARCH=${BUILD_ARCH} \
go build -o ./binaries/external-dns-midaas-webhook_${BUILD_OS}-${BUILD_ARCH} .
- name: Upload test results
- name: Upload build results
uses: actions/upload-artifact@v4
with:
name: external-dns-midaas-webhook_${BUILD_OS}-${BUILD_ARCH}
path: ./binaries/external-dns-midaas-webhook_${BUILD_OS}-${BUILD_ARCH}
name: external-dns-midaas-webhook_${{ env.BUILD_OS }}-${{ env.BUILD_ARCH }}
path: ./binaries/external-dns-midaas-webhook_${{ env.BUILD_OS }}-${{ env.BUILD_ARCH }}

build-docker:
name: Build application image
Expand Down
7 changes: 6 additions & 1 deletion .github/workflows/cache.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ on:
description: Branch name assiocited with the cache
required: false
type: string
COMMIT_SHA:
description: Commit sha assiocited with the cache
required: false
type: string

permissions:
packages: write
Expand Down Expand Up @@ -68,5 +72,6 @@ jobs:
./ci/scripts/delete-image.sh \
-o "${{ steps.image-infos.outputs.ORG_NAME }}" \
-i "${{ steps.image-infos.outputs.REPO_NAME }}" \
-t "pr-${{ inputs.PR_NUMBER || github.event.pull_request.number || github.event.number }}" \
-t "pr-${{ inputs.PR_NUMBER || inputs.COMMIT_SHA || github.event.pull_request.number || github.event.number }}" \
-t "${{ inputs.COMMIT_SHA && format('sha-{0}', inputs.COMMIT_SHA) || format('pr-{0}', inputs.PR_NUMBER || inputs.COMMIT_SHA || github.event.pull_request.number || github.event.number) }}" \
-g "${{ secrets.GITHUB_TOKEN }}"
6 changes: 3 additions & 3 deletions ci/scripts/delete-image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ IMAGE_NAME_URL_ENCODED="$(jq -rn --arg x ${IMAGE_NAME} '$x | @uri')"
IMAGES=$(curl -s \
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
"https://api.github.com/users/${ORG}/packages/container/${IMAGE_NAME_URL_ENCODED}/versions?per_page=100")
MAIN_IMAGE_ID=$(echo "$IMAGES" | jq -r --arg t "$TAG" '.[] | select(.labels["org.opencontainers.image.version"] == $t) | .id')
MAIN_IMAGE_ID=$(echo "$IMAGES" | jq -r --arg t "$TAG" '.[] | select(.metadata.container.tags[] | contains($t)) | .id')

# Delete subsequent images
while read -r SHA; do
Expand All @@ -87,7 +87,7 @@ while read -r SHA; do
curl -s \
-X DELETE \
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
"https://api.github.com/user/${ORG}/packages/container/${IMAGE_NAME_URL_ENCODED}/versions/${IMAGE_ID}"
"https://api.github.com/users/${ORG}/packages/container/${IMAGE_NAME_URL_ENCODED}/versions/${IMAGE_ID}"
done <<< "$(docker buildx imagetools inspect ghcr.io/${ORG}/${IMAGE_NAME}:${TAG} --raw | jq -r '.manifests[] | .digest')"

# Delete main image
Expand All @@ -96,4 +96,4 @@ printf "\n${red}[Delete ghcr image].${no_color} Deleting image '$ORG/$IMAGE_NAME
curl -s \
-X DELETE \
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
"https://api.github.com/user/${ORG}/packages/container/${IMAGE_NAME_URL_ENCODED}/versions/${MAIN_IMAGE_ID}"
"https://api.github.com/users/${ORG}/packages/container/${IMAGE_NAME_URL_ENCODED}/versions/${MAIN_IMAGE_ID}"

0 comments on commit 58d49fb

Please sign in to comment.