From 9145f4635dc3226b6e6b709cff8f636cc2cb07cc Mon Sep 17 00:00:00 2001 From: Nadezhda Fedorova Date: Tue, 6 Aug 2024 17:28:09 +0300 Subject: [PATCH] add workflow for single image building --- .gitea/workflows/wf_single.yaml | 146 ++++++++++++++++++++++++++++++++ 1 file changed, 146 insertions(+) create mode 100644 .gitea/workflows/wf_single.yaml diff --git a/.gitea/workflows/wf_single.yaml b/.gitea/workflows/wf_single.yaml new file mode 100644 index 0000000..836cb93 --- /dev/null +++ b/.gitea/workflows/wf_single.yaml @@ -0,0 +1,146 @@ +name: Building alt images +on: + push: + tags: + - '*_*/*' + +jobs: + build-process: + runs-on: alt-latest + outputs: + branch: ${{ env.BRANCH }} + image: ${{ env.IMAGE }} + url: ${{ env.URL }} + repo: ${{ env.REPO }} + buildres: ${{ steps.build-script.outcome }} + test: ${{ env.TEST }} + steps: + - name: Check workspace + run: | + repourl=$(echo $GU | cut -d '/' -f 3) + echo "URL=$repourl" >> ${GITHUB_ENV} + echo "URL=$repourl" + reponame=$(echo $GR | cut -d '/' -f 1) + echo "REPO=$reponame" >> ${GITHUB_ENV} + echo "REPO=$reponame" + env: + GU: ${{ gitea.server_url }} + GR: ${{ gitea.repository }} + - name: Update apt + uses: actions/init-alt-env@v1 + - name: Install requires + run: | + echo "apt-get install -y python3-module-tomli python3-module-jinja2 podman buildah jq curl" + apt-get install -y python3-module-tomli python3-module-jinja2 podman buildah jq curl + echo "apt-get install -y qemu-user-static-binfmt-aarch64 qemu-user-static-binfmt-arm qemu-user-static-binfmt-ppc" + apt-get install -y qemu-user-static-binfmt-aarch64 qemu-user-static-binfmt-arm qemu-user-static-binfmt-ppc + - name: Check out current repo + uses: actions/checkout@v4 + - name: Login podman gitea + run: | + echo "podman login ${{ env.URL }}" + podman login --username $P_USER --password $P_PASS ${{ env.URL }} + env: + P_USER: ${{ secrets.PODMAN_USER }} + P_PASS: ${{ secrets.PODMAN_PASS }} + - name: Check files in the repository + run: | + ls -a ${{ gitea.workspace }} + - name: Parse target branch and tag from events context, save to env + env: + EV: ${{ toJson(gitea.event) }} + run: | + echo $EV | jq '.ref' -r | sed "s/refs\/tags\//BRANCH=/g" | cut -d '_' -f 1 + echo $EV | jq '.ref' -r | sed "s/refs\/tags\//BRANCH=/g" | cut -d '_' -f 1 >> ${GITHUB_ENV} + localimage=$(echo $EV | jq '.ref' -r | sed 's/refs\/tags\///g' | cut -d '_' -f 2) + echo "IMAGE=$localimage" >> ${GITHUB_ENV} + echo "IMAGE=$localimage" + - name: Get test for image + run: | + if test -f ${{ gitea.workspace }}/org/$IM/test; then testscript=$(cat ${{ gitea.workspace }}/org/$IM/test); else testscript=""; fi + echo "TEST=$testscript" >> ${GITHUB_ENV} + env: + IM: ${{ env.IMAGE }} + BR: ${{ env.BRANCH }} + - name: Run building script + id: build-script + run: | + echo "build.py -i $IM -b $BR" + ${{ gitea.workspace }}/build.py -i $IM -b $BR + env: + IM: ${{ env.IMAGE }} + BR: ${{ env.BRANCH }} + continue-on-error: true + - name: Send notification if build crashed + if: ${{ steps.build-script.outcome != 'success' }} + run: | + issueid=1 + body="Building image $IM finish with some errors." + curl -X 'POST' "$URL/api/v1/repos/$REPO/image-forge/issues/$issueid/comments?token=$T" -H 'accept: application/json' -H 'Content-Type: application/json' -d "{ \"body\": \"$body\" }" -s + echo "notification about test error is sent to issue $issueid" + env: + T: ${{ secrets.TOKEN }} + BR: ${{ env.BRANCH }} + URL: ${{ gitea.server_url }} + REPO: ${{ env.REPO }} + IM: ${{ env.IMAGE }} + - name: Delete event tag + run: | + tagname=$(echo $EV | jq '.ref' -r | sed "s/refs\/tags\///g") + curl -X 'DELETE' "$URL/api/v1/repos/$REPO/image-forge/tags/$tagname?token=$T" -H 'accept: application/json' -s + echo "tag $tagname is deleted" + env: + T: ${{ secrets.TOKEN }} + BR: ${{ env.BRANCH }} + URL: ${{ gitea.server_url }} + REPO: ${{ env.REPO }} + EV: ${{ toJson(gitea.event) }} + test-process: + needs: build-process + if: ${{ needs.build-process.outputs.buildres == 'success' }} + runs-on: alt-latest + steps: + - name: Update apt + uses: https://gitea.basealt.ru/actions/init-alt-env@v1 + - name: Install requires + run: | + echo "apt-get install -y python3-module-tomli python3-module-jinja2 podman buildah curl" + apt-get install -y python3-module-tomli python3-module-jinja2 podman buildah curl + - name: Run test + id: test-script + if: ${{ needs.build-process.outputs.test != '' }} + continue-on-error: true + run: podman run --rm --entrypoint=\"/bin/sh\" $URL/$REPO/$IM:$BR -c \"$TEST\" + env: + IM: ${{ needs.build-process.outputs.image }} + BR: ${{ needs.build-process.outputs.branch }} + URL: ${{ needs.build-process.outputs.url }} + REPO: ${{ needs.build-process.outputs.repo }} + TEST: ${{ needs.build-process.outputs.test }} + - name: Run special test + id: special-test + if: ${{ needs.build-process.outputs.test == '' }} + continue-on-error: true + run: | + if [[ IM = 'alt/distroless-true' ]]; then podman run --rm $URL/$REPO/$IM:$BR true; fi + if [[ IM = 'alt/distroless-gotop' ]]; then podman run --rm $URL/$REPO/$IM:$BR --version; fi + env: + IM: ${{ needs.build-process.outputs.image }} + BR: ${{ needs.build-process.outputs.branch }} + URL: ${{ needs.build-process.outputs.url }} + REPO: ${{ needs.build-process.outputs.repo }} + - name: Send notification if test crashed + if: ${{ steps.test-script.outcome == 'failure' || steps.special-test.outcome == 'failure' }} + run: | + issueid=1 + errors=$(cat errors.log) + body="Testing image $IM finish with some errors." + curl -X 'POST' "$URL/api/v1/repos/$REPO/image-forge/issues/$issueid/comments?token=$T" -H 'accept: application/json' -H 'Content-Type: application/json' -d "{ \"body\": \"$body\" }" -s + echo "notification about test error is sent to issue $issueid" + env: + T: ${{ secrets.TOKEN }} + BR: ${{ needs.build-process.outputs.branch }} + URL: ${{ gitea.server_url }} + REPO: ${{ needs.build-process.outputs.repo }} + IM: ${{ needs.build-process.outputs.image }} +