commit 16385091f8df08dc50fdec045dfb2fcbd428b5a6 Author: Nadezhda Fedorova Date: Fri Apr 12 13:10:21 2024 +0300 add action diff --git a/README.md b/README.md new file mode 100644 index 0000000..bde4863 --- /dev/null +++ b/README.md @@ -0,0 +1,16 @@ +# Action for test images + +- use it to test images after building + +# Usage + + +```yaml +- uses: actions/image-forge-test +with: + image: '' + branch: '' + url: '' + repo: '' +``` + diff --git a/action.yaml b/action.yaml new file mode 100644 index 0000000..9428c75 --- /dev/null +++ b/action.yaml @@ -0,0 +1,80 @@ +name: 'Reusable test job' +description: 'Test for images' + +outputs: + result: + description: "Result of test (success|failure)" + value: ${{ jobs.example_job.outputs.output1 }} +inputs: + image: string + branch: string + org: string + url: string + repo: string + +runs: + using: 'composite' + 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" + 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: Check out building repo + uses: https://gitea.com/actions/checkout@v4 + with: + repository: ${{ gitea.server_url }}/${{ inputs.repo }}/gitea-image-forge + - name: Get test for image + run: | + if test -f gitea-image-forge/org/$ORG/$IM/test; then testscript=$(cat ${{ gitea.workspace }}/org/$ORG/$IM/test); else testscript=""; fi + echo "TEST=$testscript" >> ${GITHUB_ENV} + echo "test script: $testscript" + if [[ $ORG == 'k8s' ]]; then echo "IMAGEPATH=$ORG-$BR/$IM" >> ${GITHUB_ENV}; else echo "IMAGEPATH=$ORG/$IM" >> ${GITHUB_ENV}; fi + env: + IM: ${{ inputs.image }} + ORG: ${{ inputs.org }} + BR: ${{ inputs.branch }} + - name: Run test + id: test-script + if: ${{ env.TEST != '' }} + continue-on-error: true + uses: https://gitea.basealt.ru/actions/podman-run-action@v2 + with: + image: ${{ inputs.url }}/${{ inputs.repo }}/${{ env.IMAGEPATH }}:${{ inputs.branch }} + options: --rm + run: ${{ env.TEST }} + - name: Run special test + id: special-test + if: ${{ env.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: ${{ inputs.image }} + BR: ${{ inputs.branch }} + URL: ${{ inputs.url }} + - name: Send notification if test crashed + if: ${{ steps.test-script.outcome == 'failure' || steps.special-test.outcome == 'failure' }} + run: | + issueid=$(curl -X 'GET' "$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) + body="Building of image $IM, branch $BR, org $ORG is failed" + curl -X 'POST' "$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 about test error is sent to issue $issueid" + env: + T: ${{ secrets.TOKEN }} + URL: ${{ gitea.server_url }} + IM: ${{ inputs.image }} + ORG: ${{ inputs.org }} + BR: ${{ inputs.branch }} + REPO: ${{ inputs.repo }} + - name: Finish test + run: echo "finish test for image $IM, branch $BR, org $ORG" + env: + IM: ${{ inputs.image }} + BR: ${{ inputs.branch }} + ORG: ${{ inputs.org }} +