# action.yml name: 'Reusable test job' description: 'Test for images' inputs: image: description: 'Name image for test' branch: description: 'Branch of image for test' default: 'p10' org: description: 'alt or k8s' default: 'alt' url: description: 'Alt-gitea url' default: 'https://gitea.basealt.ru/' repo: description: 'Repo with building script' default: 'image-forge' runs: using: 'composite' steps: - name: Check inputs run: | echo "image=${{ inputs.image }}" echo "branch=${{ inputs.branch }}" echo "org=${{ inputs.org }}" - name: Check out building repo uses: https://gitea.com/actions/checkout@v4 with: ref: master repository: ${{ inputs.repo }}/gitea-image-forge github-server-url: ${{ gitea.server_url }} - name: Get test for image run: | if test -f gitea-image-forge/org/$ORG/$IM/test; then testscript=$(cat gitea-image-forge/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:${{ inputs.branch }}" >> ${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 }} 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 }}