docker-act_runner/.github/workflows/build.yaml

60 lines
2.2 KiB
YAML
Raw Permalink Normal View History

name: Build Container and update Flux
2024-03-29 02:24:03 +00:00
on:
push:
branches:
- '*'
- '!k-*'
env:
DEPLOY_MANIFEST: "${{ vars.DEPLOY_MANIFEST || 'deploy.yaml' }}"
FLUX_MANIFEST: "${{ vars.FLUX_MANIFEST || 'flux.yaml' }}"
2024-02-25 19:51:06 +00:00
jobs:
Explore-Gitea-Actions:
runs-on: metal-docker
steps:
- name: Check out repository code
uses: actions/checkout@v3
- run: |
ls -la
docker build --progress plain --iidfile iid.txt .
stringprefix() { [ ${#1} -le $2 ] && echo $1 && return 0 || stringprefix "${1%?}" $2 ; }
2024-03-29 02:24:03 +00:00
STAG="$GITHUB_REF_NAME-$(date +%Y-%m-%d-%H.%M.%S)"
2024-02-25 19:51:06 +00:00
SHORTSHA="$(stringprefix "$GITHUB_SHA" 8)"
2024-03-29 02:24:03 +00:00
for TAG in "$SHORTSHA" "$GITHUB_REF_NAME" "$STAG";do
2024-02-25 19:51:06 +00:00
docker tag "`cat iid.txt`" "$DOCKER_REGISTRY/$GITHUB_REPOSITORY:$TAG"
docker push "$DOCKER_REGISTRY/$GITHUB_REPOSITORY:$TAG"
done
BRANCH="$GITHUB_REF_NAME"
KBRANCH="k-$GITHUB_REF_NAME"
2024-03-29 02:24:03 +00:00
git config user.name "$GITHUB_REPOSITORY (act)"
git config user.email "gitea-actions@strudelline.net"
# let's fix the origin branch's flux.yaml if it's needed.
# this will only happen once so it's not such an awful UX.
sed -i -e "s@branch: .*@branch: $KBRANCH@" "k/$FLUX_MANIFEST"
if git diff | grep -q .;then
echo fixing branch in flux.yaml of the origin branch
git add "k/$FLUX_MANIFEST"
git commit -m "fix $FLUX_MANIFEST in $BRANCH"
fi
# ensure the k-branch exists so we can ensure it's deleted. no errors at all.
git checkout -B "$KBRANCH"
git checkout "$BRANCH"
git branch -D "$KBRANCH"
git checkout -b "$KBRANCH"
# now fix up the images in k/runner.yaml
sed -i -e "s@image: $DOCKER_REGISTRY/$GITHUB_REPOSITORY:.*@image: $DOCKER_REGISTRY/$GITHUB_REPOSITORY:$STAG@" "k/$DEPLOY_MANIFEST"
git add k
2024-03-29 02:24:03 +00:00
git commit -m "upgrade runner sts to $STAG"
# now, since we've made it here, we'll push both, k-branch forced because it's supposed to overwrite history
git push -f origin "$KBRANCH"
git push origin "$BRANCH"