2024-08-06 17:28:09 +03:00
name : Building alt images
on :
push :
tags :
2024-11-11 12:27:59 +03:00
- '*_*/*_*'
2024-08-06 17:28:09 +03:00
jobs :
build-process :
2024-11-11 18:58:45 +03:00
runs-on : alt-sisyphus
2024-08-06 17:28:09 +03:00
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 }}
2024-09-18 12:59:27 +03:00
- name : Set repo for c10f2 (Temporary)
if : ${{ contains(github.ref_name, 'c10f2') }}
run : |
echo "event tag=${{ github.ref_name }}"
echo "10.4.0.3 update.altsp.su" >> /etc/hosts
echo "cat /etc/hosts"
cat /etc/hosts
2024-08-06 17:28:09 +03:00
- name : Update apt
uses : actions/init-alt-env@v1
- name : Install requires
run : |
2024-11-11 16:37:04 +03:00
echo "apt-get install -y python3-module-tomli python3-module-jinja2 python3-module-yaml python3-module-requests podman buildah jq curl"
apt-get install -y python3-module-tomli python3-module-jinja2 python3-module-yaml python3-module-requests podman buildah jq curl
2024-11-05 16:54:11 +03:00
echo "apt-get install -y qemu-user-static-binfmt-aarch64 qemu-user-static-binfmt-arm qemu-user-static-binfmt-ppc qemu-user-static-binfmt-riscv qemu-user-static-binfmt-loongarch"
apt-get install -y qemu-user-static-binfmt-aarch64 qemu-user-static-binfmt-arm qemu-user-static-binfmt-ppc qemu-user-static-binfmt-riscv qemu-user-static-binfmt-loongarch
2024-08-06 17:28:09 +03:00
- 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 :
2024-11-11 18:04:27 +03:00
P_USER : ${{ secrets.PODMAN_USER }}
2024-08-06 17:28:09 +03:00
P_PASS : ${{ secrets.PODMAN_PASS }}
- name : Check files in the repository
run : |
2024-11-11 12:27:59 +03:00
ls -a ${{ gitea.workspace }}
2024-08-06 17:28:09 +03:00
- name : Parse target branch and tag from events context, save to env
env :
2024-11-11 12:27:59 +03:00
EV : ${{ toJson(gitea.event) }}
2024-08-06 17:28:09 +03:00
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)
2024-11-11 12:27:59 +03:00
echo "IMAGE=$localimage" >> ${GITHUB_ENV}
2024-09-26 17:04:25 +03:00
echo "IMAGE=$localimage"
org=$(echo "$localimage" | cut -d '/' -f 1)
echo "ORG=$org" >> ${GITHUB_ENV}
echo "ORG=$org"
2024-11-11 12:27:59 +03:00
ver=$(echo $EV | jq '.ref' -r | sed 's/refs\/tags\///g' | cut -d '_' -f 3)
echo "VER=$ver" >> ${GITHUB_ENV}
echo "VER=$ver"
2024-08-06 17:28:09 +03:00
- 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
2024-11-11 12:27:59 +03:00
echo "TEST=$testscript" >> ${GITHUB_ENV}
env :
2024-08-06 17:28:09 +03:00
IM : ${{ env.IMAGE }}
BR : ${{ env.BRANCH }}
- name : Run building script
id : build-script
run : |
2024-11-11 17:32:27 +03:00
if [[ "$IM" == *"k8s"* ]]; then k8sarg="--overwrite-organization $ORG-$BR --package-versions {\"$IM\":\"$VER\"}"; else k8sarg=""; fi
2024-11-11 18:29:43 +03:00
if [[ "$BR" == "sisyphus" ]]; then arches="--arches amd64 386 arm64 loong64"; else arches="--arches amd64 386 arm64"; fi
echo "build.py -i $IM -b $BR $arches $k8sarg"
2024-11-11 12:27:59 +03:00
${{ gitea.workspace }}/build.py -i $IM -b $BR $arches $k8sarg
2024-08-06 17:28:09 +03:00
env :
IM : ${{ env.IMAGE }}
2024-11-11 12:27:59 +03:00
VER : ${{ env.VER }}
2024-08-06 17:28:09 +03:00
BR : ${{ env.BRANCH }}
2024-09-26 17:04:25 +03:00
ORG : ${{ env.ORG }}
2024-08-06 17:28:09 +03:00
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
2024-11-11 12:27:59 +03:00
echo "notification about test error is sent to issue $issueid"
2024-08-06 17:28:09 +03:00
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
2024-11-11 12:27:59 +03:00
echo "tag $tagname is deleted"
2024-08-06 17:28:09 +03:00
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' }}
2024-11-11 18:58:45 +03:00
runs-on : alt-sisyphus
2024-08-06 17:28:09 +03:00
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
2024-08-07 17:05:10 +03:00
run : |
2024-09-27 16:47:11 +03:00
if [[ "$IM" == *"k8s"* ]]; then echo "skip tests for k8s images"; else podman run --rm --entrypoint="/bin/sh" $URL/$IM:$BR -c "$TEST"; fi
2024-11-11 12:27:59 +03:00
env :
2024-08-06 17:28:09 +03:00
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 : |
2024-08-07 17:05:10 +03:00
if [[ $IM = 'alt/distroless-true' ]]; then podman run --rm $URL/$IM:$BR true; fi
if [[ $IM = 'alt/distroless-gotop' ]]; then podman run --rm $URL/$IM:$BR --version; fi
2024-08-06 17:28:09 +03:00
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 }}