This commit is contained in:
Nadezhda Fedorova 2024-04-10 12:31:30 +03:00
parent 4250455f66
commit 55d9707d24
5 changed files with 73 additions and 45 deletions

View File

@ -5,8 +5,15 @@ on:
- '*_*/*' - '*_*/*'
jobs: jobs:
Building_process: build_process:
runs-on: alt-latest 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: steps:
- name: Check workspace - name: Check workspace
run: | run: |
@ -23,12 +30,12 @@ jobs:
apt-get update -y && apt-get install -y apt rpm apt-get update -y && apt-get install -y apt rpm
- name: Install requires - name: Install requires
run: | run: |
echo "apt-get install -y python3-module-tomli python3-module-jinja2 podman buildah curl jq" echo "apt-get install -y python3-module-tomli python3-module-jinja2 podman buildah jq"
apt-get install -y python3-module-tomli python3-module-jinja2 podman buildah curl jq apt-get install -y python3-module-tomli python3-module-jinja2 podman buildah jq
echo "apt-get install -y qemu-user-static-binfmt-aarch64 qemu-user-static-binfmt-arm qemu-user-static-binfmt-ppc" 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 apt-get install -y qemu-user-static-binfmt-aarch64 qemu-user-static-binfmt-arm qemu-user-static-binfmt-ppc
- name: Check out current repo - name: Check out current repo
uses: actions/checkout@v3 uses: https://gitea.com/actions/checkout@v4
- name: Login podman gitea - name: Login podman gitea
run: | run: |
echo "podman login ${{ env.URL }}" echo "podman login ${{ env.URL }}"
@ -49,9 +56,9 @@ jobs:
echo "IMAGE=$localimage" >> ${GITHUB_ENV} echo "IMAGE=$localimage" >> ${GITHUB_ENV}
echo "IMAGE=$localimage" echo "IMAGE=$localimage"
- name: Get test for image - name: Get test for image
run: | run: |
cat ${{ gitea.workspace }}/org/$IM/test >> ${GITHUB_ENV} testscript=$(cat ${{ gitea.workspace }}/org/$IM/test)
echo "TEST=$testscript">> ${GITHUB_ENV}
env: env:
IM: ${{ env.IMAGE }} IM: ${{ env.IMAGE }}
BR: ${{ env.BRANCH }} BR: ${{ env.BRANCH }}
@ -64,46 +71,66 @@ jobs:
IM: ${{ env.IMAGE }} IM: ${{ env.IMAGE }}
BR: ${{ env.BRANCH }} BR: ${{ env.BRANCH }}
continue-on-error: true continue-on-error: true
- name: Run test test_process:
id: images_test if: ${{ jobs.build_process.env.BUILDRES == 'success' }}
if: ${{ steps.build_script.outcome == 'success' }} needs: build_process
continue-on-error: true runs-on: alt-latest
uses: fmidev/podman-run-action@v1 outputs:
with: testres: ${{ steps.test_script.outcome }}
image: ${{ env.url }}/${{ env.REPO }}/${{ env.IMAGE }}:${{ env.BRANCH }} steps:
shell: bash - name: Update apt
options: --rm --log-level trace
run: | run: |
echo "${{ env.TEST }}" echo "apt-get update -y && apt-get install -y apt rpm"
${{ env.TEST }} apt-get update -y && apt-get install -y apt rpm
- name: Install requires
run: |
echo "apt-get install -y python3-module-tomli python3-module-jinja2 podman buildah"
apt-get install -y python3-module-tomli python3-module-jinja2 podman buildah
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: Run test
id: test_script
continue-on-error: true
uses: https://gitea.basealt.ru/actions/podman-run-action@v2
with:
image: ${{ needs.build_process.outputs.url }}/${{ needs.build_process.outputs.repo }}/${{ needs.build_process.outputs.image }}:${{ needs.build_process.outputs.branch }}
options: --rm
run: ${{ needs.build_process.outputs.test }}
finish_process:
needs: [ build_process, test_process ]
runs-on: alt-latest
steps:
- name: Update apt
run: |
echo "apt-get update -y && apt-get install -y apt rpm"
apt-get update -y && apt-get install -y apt rpm
- name: Update apt
run: |
echo "apt-get install -y curl jq"
apt-get install -y curl jq
- name: Delete event tag - name: Delete event tag
run: | run: |
tagname=$(echo $EV | jq '.ref' -r | sed "s/refs\/tags\///g") tagname=$(echo $EV | jq '.ref' -r | sed "s/refs\/tags\///g")
echo "https://$URL/api/v1/repos/$REPO/gitea-image-forge/tags/$tagname?token=$T"
curl -X 'DELETE' "https://$URL/api/v1/repos/$REPO/gitea-image-forge/tags/$tagname?token=$T" -H 'accept: application/json' -s curl -X 'DELETE' "https://$URL/api/v1/repos/$REPO/gitea-image-forge/tags/$tagname?token=$T" -H 'accept: application/json' -s
echo "tag $BR_$IM is deleted" echo "tag $BR_$IM is deleted"
env: env:
T: ${{ secrets.TOKEN }} T: ${{ secrets.TOKEN }}
URL: ${{ env.URL }} URL: ${{ needs.build_process.outputs.url }}
REPO: ${{ env.REPO }} REPO: ${{ needs.build_process.outputs.repo }}
IM: ${{ env.IMAGE }} IM: ${{ needs.build_process.outputs.image}}
BR: ${{ env.BRANCH }} BR: ${{ needs.build_process.outputs.branch }}
EV: ${{ toJson(gitea.event) }} EV: ${{ toJson(gitea.event) }}
continue-on-error: true continue-on-error: true
- name: Send comment to issue for notification - name: Send comment to issue for notification
run: | run: |
echo "https://$URL/api/v1/repos/$REPO/gitea-image-forge/issues?state=all&type=issues&page=1&limit=1&token=$T"
issueid=$(curl -X 'GET' "https://$URL/api/v1/repos/$REPO/gitea-image-forge/issues?state=all&type=issues&page=1&limit=1&token=$T" -H 'accept: application/json' -s | jq '.[].number' -r) issueid=$(curl -X 'GET' "https://$URL/api/v1/repos/$REPO/gitea-image-forge/issues?state=all&type=issues&page=1&limit=1&token=$T" -H 'accept: application/json' -s | jq '.[].number' -r)
if [[ ${{ steps.build_script.outcome == 'success' && steps.images_test.outcome == 'success' }} ]]; then body="Building of image $IM for branch $BR finished success"; else body="Testing of image $IM for branch $BR is failed"; fi if [[ ${ needs.build_process.outputs.buildres }} = "success" ]] && [[ ${{ needs.test_process.outputs.testres }} = "success" ]]; then body="Building of image $IM for branch $BR finished success"; else body="Testing of image $IM for branch $BR is failed"; fi
if [[ ${{ steps.build_script.outcome == 'failure' }} ]]; then body="Building of image $IM for branch $BR is failed"; fi if [[ ${{ needs.build_process.outputs.buildres }} != 'success' ]]; then body="Building of image $IM for branch $BR is failed"; fi
echo "https://$URL/api/v1/repos/$REPO/gitea-image-forge/issues/$issueid/comments?token=$T"
curl -X 'POST' "https://$URL/api/v1/repos/$REPO/gitea-image-forge/issues/$issueid/comments?token=$T" -H 'accept: application/json' -H 'Content-Type: application/json' -d "{ \"body\": \"$body\" }" -s curl -X 'POST' "https://$URL/api/v1/repos/$REPO/gitea-image-forge/issues/$issueid/comments?token=$T" -H 'accept: application/json' -H 'Content-Type: application/json' -d "{ \"body\": \"$body\" }" -s
echo "notification is sent" echo "notification is sent"
env: env:
T: ${{ secrets.TOKEN }} T: ${{ secrets.TOKEN }}
URL: ${{ env.URL }} URL: ${{ needs.build_process.outputs.url }}
REPO: ${{ env.REPO }} REPO: ${{ needs.build_process.outputs.repo }}
IM: ${{ env.IMAGE }} IM: ${{ needs.build_process.outputs.image}}
BR: ${{ env.BRANCH }} BR: ${{ needs.build_process.outputs.image}}
- name: Check status
run: echo "This job's status is ${{ job.status }}"

View File

@ -1,23 +1,23 @@
name: Test event wf name: Test_wf
on: on:
push: push:
tags: tags:
- '*' - '*'
jobs: jobs:
Test event: Test-job:
runs-on: alt-latest runs-on: alt-latest
env:
TEST: "gitea --version"
steps: steps:
- name: Update apt - name: Update apt
run: apt-get update -y && apt-get install -y apt rpm run: apt-get update -y && apt-get install -y apt rpm
- name: Install jq - name: Install reqs
run: apt-get install -y jq run: apt-get install -y podman buildah
- name: Get event context and parse tag name - name: Podman run
env: uses: https://gitea.basealt.ru/actions/podman-run-action@v2
EV: ${{ toJson(gitea.event) }} with:
run: | image: gitea.basealt.ru/images_repo/alt/gitea
echo $EV | jq '.ref' -r | sed 's/refs\/tags\//tag=/g' options: --rm
echo $EV | jq '.ref' -r | sed 's/refs\/tags\//NEW_TAG=/g' >> ${GITHUB_ENV} run: ${{ env.TEST }}
- name: Run script
run: echo "${{ env.NEW_TAG }}"
- run: echo "This job's status is ${{ job.status }}" - run: echo "This job's status is ${{ job.status }}"

1
org/alt/apache2/test Normal file
View File

@ -0,0 +1 @@
apachectl -v

View File

@ -1 +1 @@
TEST="gitea --version" gitea --version

View File

@ -1 +1 @@
TEST="pyhon3 --help" python3 --help