diff --git a/.github/workflows/bot_run_tests.yml b/.github/workflows/bot_run_tests.yml index c0b5cf0..ba867ed 100644 --- a/.github/workflows/bot_run_tests.yml +++ b/.github/workflows/bot_run_tests.yml @@ -3,10 +3,10 @@ on: issue_comment jobs: pr_commented: - name: Run Tests for PR + name: Check Permissions if: > github.event.issue.pull_request && - contains(github.event.issue.bodyText, '/run tests') + contains(github.event.comment.body, '/run tests') runs-on: ubuntu-latest steps: - name: Check association @@ -14,9 +14,21 @@ jobs: allowed=("OWNER" "COLLABORATOR") value="\<${{ github.event.issue.author_association }}\>" - if [[ ${array[@]} =~ $value ]] + if [[ ${allowed[@]} =~ $value ]] then exit 0 else exit 1 fi + + run-tests: + name: Run Tests + permissions: + contents: read + packages: write + statuses: write + needs: + - pr_commented + uses: ./.github/workflows/build-and-test.yml + with: + pr: ${{ github.event.issue.number }} \ No newline at end of file diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index fa5c18e..7b90bfc 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -6,11 +6,14 @@ on: - 'main' tags: - 'v*' - - workflow_run: - workflows: [Run Tests on PR] - types: - - completed + + pull_request: + + workflow_call: + inputs: + pr: + required: true + type: string concurrency: @@ -33,21 +36,54 @@ jobs: build-container: if: > github.event_name == 'push' || - ( github.event.workflow_run.event == 'pull_request' && - github.event.workflow_run.conclusion == 'success' ) + github.event_name == 'issue_comment' || + ( github.event_name == 'pull_request' && + contains(github.event.pull_request.labels.*.name, 'auto-test') ) name: Build Container Image + env: + JOB_NAME: Build Container Image runs-on: ubuntu-latest permissions: contents: read packages: write + statuses: write steps: - - name: Checkout repo + - name: Checkout uses: actions/checkout@v4 with: submodules: recursive fetch-depth: 0 fetch-tags: 'true' + - name: Switch branch + if: inputs.pr + env: + GITHUB_USER: ${{ github.actor }} + GITHUB_TOKEN: ${{ github.token }} + run: | + sudo apt-get update + sudo apt-get install -y hub + hub pr checkout ${{ inputs.pr }} + echo "sha=$(git rev-parse HEAD)" >> $GITHUB_ENV + + - name: Get Current Job Log URL + if: inputs.pr && always() + uses: Tiryoh/gha-jobid-action@v1 + id: jobs + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + job_name: "Run Tests / ${{ env.JOB_NAME }}" + + - name: Set status + if: inputs.pr && always() + uses: myrotvorets/set-commit-status-action@v2.0.1 + with: + token: ${{ secrets.GITHUB_TOKEN }} + status: ${{ job.status }} + context: ${{ env.JOB_NAME }} + sha: ${{ env.sha }} + targetUrl: ${{ steps.jobs.outputs.html_url }} + - name: Docker meta id: meta uses: docker/metadata-action@v5 @@ -75,15 +111,28 @@ jobs: tags: ${{ steps.build-image.outputs.tags }} username: ${{ github.actor }} password: ${{ github.token }} + + - name: Set status + if: inputs.pr && always() + uses: myrotvorets/set-commit-status-action@v2.0.1 + with: + token: ${{ secrets.GITHUB_TOKEN }} + status: ${{ job.status }} + context: ${{ env.JOB_NAME }} + sha: ${{ env.sha }} + targetUrl: ${{ steps.jobs.outputs.html_url }} build-and-push-iso: name: Build ISO + env: + JOB_NAME: Build ISO runs-on: ubuntu-latest needs: - build-container permissions: contents: read packages: write + statuses: write continue-on-error: false strategy: fail-fast: false @@ -97,8 +146,39 @@ jobs: iso_name-39: ${{ steps.save_output.outputs.iso_name-39 }} iso_name-40: ${{ steps.save_output.outputs.iso_name-40 }} steps: - - name: Checkout repo + - name: Checkout uses: actions/checkout@v4 + with: + submodules: recursive + + - name: Switch branch + if: inputs.pr + env: + GITHUB_USER: ${{ github.actor }} + GITHUB_TOKEN: ${{ github.token }} + run: | + sudo apt-get update + sudo apt-get install -y hub + hub pr checkout ${{ inputs.pr }} + echo "sha=$(git rev-parse HEAD)" >> $GITHUB_ENV + + - name: Get Current Job Log URL + if: inputs.pr && always() + uses: Tiryoh/gha-jobid-action@v1 + id: jobs + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + job_name: "Run Tests / ${{ env.JOB_NAME }}" + + - name: Set status + if: inputs.pr && always() + uses: myrotvorets/set-commit-status-action@v2.0.1 + with: + token: ${{ secrets.GITHUB_TOKEN }} + status: ${{ job.status }} + context: ${{ env.JOB_NAME }} + sha: ${{ env.sha }} + targetUrl: ${{ steps.jobs.outputs.html_url }} - name: Lowercase Registry id: registry_case @@ -148,13 +228,26 @@ jobs: compression-level: 0 overwrite: true + - name: Set status + if: inputs.pr && always() + uses: myrotvorets/set-commit-status-action@v2.0.1 + with: + token: ${{ secrets.GITHUB_TOKEN }} + status: ${{ job.status }} + context: ${{ env.JOB_NAME }} + sha: ${{ env.sha }} + targetUrl: ${{ steps.jobs.outputs.html_url }} + test-iso: name: Test ISO + env: + JOB_NAME: Test ISO runs-on: ubuntu-latest needs: - build-and-push-iso permissions: contents: read + statuses: write continue-on-error: false strategy: fail-fast: false @@ -164,11 +257,40 @@ jobs: - 39 - 40 steps: - - name: Checkout repo + - name: Checkout uses: actions/checkout@v4 with: submodules: recursive + - name: Switch branch + if: inputs.pr + env: + GITHUB_USER: ${{ github.actor }} + GITHUB_TOKEN: ${{ github.token }} + run: | + sudo apt-get update + sudo apt-get install -y hub + hub pr checkout ${{ inputs.pr }} + echo "sha=$(git rev-parse HEAD)" >> $GITHUB_ENV + + - name: Get Current Job Log URL + if: inputs.pr && always() + uses: Tiryoh/gha-jobid-action@v1 + id: jobs + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + job_name: "Run Tests / ${{ env.JOB_NAME }}" + + - name: Set status + if: inputs.pr && always() + uses: myrotvorets/set-commit-status-action@v2.0.1 + with: + token: ${{ secrets.GITHUB_TOKEN }} + status: ${{ job.status }} + context: ${{ env.JOB_NAME }} + sha: ${{ env.sha }} + targetUrl: ${{ steps.jobs.outputs.html_url }} + - name: Install test tools run: | sudo apt-get update @@ -199,13 +321,26 @@ jobs: SECURE_BOOT_KEY_URL=${{ env.SECURE_BOOT_KEY_URL }} \ ENROLLMENT_PASSWORD=${{ env.ENROLLMENT_PASSWORD }} + - name: Set status + if: inputs.pr && always() + uses: myrotvorets/set-commit-status-action@v2.0.1 + with: + token: ${{ secrets.GITHUB_TOKEN }} + status: ${{ job.status }} + context: ${{ env.JOB_NAME }} + sha: ${{ env.sha }} + targetUrl: ${{ steps.jobs.outputs.html_url }} + test-deployment: name: Test deployment + env: + JOB_NAME: Test deployment runs-on: ubuntu-latest needs: - build-and-push-iso permissions: contents: read + statuses: write continue-on-error: false strategy: fail-fast: false @@ -215,11 +350,40 @@ jobs: - 39 - 40 steps: - - name: Checkout repo + - name: Checkout uses: actions/checkout@v4 with: submodules: recursive + - name: Switch branch + if: inputs.pr + env: + GITHUB_USER: ${{ github.actor }} + GITHUB_TOKEN: ${{ github.token }} + run: | + sudo apt-get update + sudo apt-get install -y hub + hub pr checkout ${{ inputs.pr }} + echo "sha=$(git rev-parse HEAD)" >> $GITHUB_ENV + + - name: Get Current Job Log URL + if: inputs.pr && always() + uses: Tiryoh/gha-jobid-action@v1 + id: jobs + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + job_name: "Run Tests / ${{ env.JOB_NAME }}" + + - name: Set status + if: inputs.pr && always() + uses: myrotvorets/set-commit-status-action@v2.0.1 + with: + token: ${{ secrets.GITHUB_TOKEN }} + status: ${{ job.status }} + context: ${{ env.JOB_NAME }} + sha: ${{ env.sha }} + targetUrl: ${{ steps.jobs.outputs.html_url }} + - name: Install test tools run: | sudo apt-get update @@ -315,3 +479,13 @@ jobs: SECURE_BOOT_KEY_URL=${{ env.SECURE_BOOT_KEY_URL }} \ ENROLLMENT_PASSWORD=${{ env.ENROLLMENT_PASSWORD }} kill $QEMU_PID + + - name: Set status + if: inputs.pr && always() + uses: myrotvorets/set-commit-status-action@v2.0.1 + with: + token: ${{ secrets.GITHUB_TOKEN }} + status: ${{ job.status }} + context: ${{ env.JOB_NAME }} + sha: ${{ env.sha }} + targetUrl: ${{ steps.jobs.outputs.html_url }}