From 17bd693f91a938337b8af6706af9ee2dfb6f831a Mon Sep 17 00:00:00 2001 From: Radek Vykydal Date: Thu, 7 Mar 2024 13:35:51 +0100 Subject: [PATCH] Add /test-platforms GH workflow --- .github/workflows/test-platforms.yml | 142 +++++++++++++++++++++++++++ 1 file changed, 142 insertions(+) create mode 100644 .github/workflows/test-platforms.yml diff --git a/.github/workflows/test-platforms.yml b/.github/workflows/test-platforms.yml new file mode 100644 index 00000000..b2815051 --- /dev/null +++ b/.github/workflows/test-platforms.yml @@ -0,0 +1,142 @@ +# Run kickstart tests in a PR triggered by a "/test-platforms" command from an organization member +# +# /test-platforms - tests all tests affected by the PR or smoke tests if there is no such +# Or specify tests by combination of test names and/or options: +# /test-platforms --testtype TESTTYPE --skip-testtypes TYPE[,TYPE..] TEST1 TEST2 +name: test-platforms +on: + issue_comment: + types: [created] + +permissions: + contents: read + statuses: write + +jobs: + pr-info: + if: startsWith(github.event.comment.body, '/test-platforms') + runs-on: ubuntu-latest + steps: + - name: Query comment author repository permissions + uses: octokit/request-action@v2.x + id: user_permission + with: + route: GET /repos/${{ github.repository }}/collaborators/${{ github.event.sender.login }}/permission + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + # restrict running of tests to users with admin or write permission for the repository + # see https://docs.github.com/en/free-pro-team@latest/rest/reference/repos#get-repository-permissions-for-a-user + # store output if user is allowed in allowed_user job output so it has to be checked in downstream job + - name: Check if user does have correct permissions + if: contains('admin write', fromJson(steps.user_permission.outputs.data).permission) + id: check_user_perm + run: | + echo "User '${{ github.event.sender.login }}' has permission '${{ fromJson(steps.user_permission.outputs.data).permission }}' allowed values: 'admin', 'write'" + echo "allowed_user=true" >> $GITHUB_OUTPUT + + - name: Get information for pull request + uses: octokit/request-action@v2.x + id: pr_api + with: + route: GET /repos/${{ github.repository }}/pulls/${{ github.event.issue.number }} + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Parse launch arguments + id: parse_launch_args + # Do not use comment body directly in the shell command to avoid possible code injection. + env: + BODY: ${{ github.event.comment.body }} + run: | + # extract first line and cut out the "/kickstart-tests" first word + LAUNCH_ARGS=$(echo "$BODY" | sed -n '1 s/^[^ ]* *//p' | sed 's/[[:space:]]*$//') + echo "launch arguments are: $LAUNCH_ARGS" + echo "launch_args=${LAUNCH_ARGS}" >> $GITHUB_OUTPUT + + # - name: Set KS test arguments + # id: ks_test_args + # run: | + # set -eux + # TARGET_BRANCH="${{ fromJson(steps.pr_api.outputs.data).base.ref }}" + # + # if [ "$TARGET_BRANCH" == "master" ]; then + # echo "skip_tests=skip-on-fedora" >> $GITHUB_OUTPUT + # echo "platform=fedora_rawhide" >> $GITHUB_OUTPUT + # elif echo "$TARGET_BRANCH" | grep -qE "fedora-[[:digit:]]+$"; then + # echo "skip_tests=skip-on-fedora" >> $GITHUB_OUTPUT + # echo "platform=fedora_rawhide" >> $GITHUB_OUTPUT + # elif echo "$TARGET_BRANCH" | grep -qE "rhel-8(\.[[:digit:]]+)?$"; then + # echo "skip_tests=skip-on-rhel,skip-on-rhel-8" >> $GITHUB_OUTPUT + # echo "platform=rhel8" >> $GITHUB_OUTPUT + # elif echo "$TARGET_BRANCH" | grep -qE "rhel-9(\.[[:digit:]]+)?$"; then + # echo "skip_tests=skip-on-rhel,skip-on-rhel-9" >> $GITHUB_OUTPUT + # echo "platform=rhel9" >> $GITHUB_OUTPUT + # else + # echo "Branch $TARGET_BRANCH is not supported by kickstart tests yet!" + # exit 1 + # fi + + outputs: + allowed_user: ${{ steps.check_user_perm.outputs.allowed_user }} + base_ref: ${{ fromJson(steps.pr_api.outputs.data).base.ref }} + sha: ${{ fromJson(steps.pr_api.outputs.data).head.sha }} + # TODO: generate test names + launch_args: ${{ steps.parse_launch_args.outputs.launch_args }} + # skip_tests: ${{ steps.ks_test_args.outputs.skip_tests }} + # platform: ${{ steps.ks_test_args.outputs.platform }} + + + platform: + needs: pr-info + if: needs.pr-info.outputs.allowed_user == 'true' && ! contains(github.event.comment.body, '--waive') + name: Run tests on the platform + runs-on: [self-hosted, kstest-test] + env: + TARGET_BRANCH: ${{ needs.pr-info.outputs.base_ref }} + strategy: + matrix: + #platform: [daily-iso, rhel8, rhel9] + platform: [daily-iso] + fail-fast: false + + steps: + - name: DUMMY + run: | + echo "Running platform ${{ matrix.platform }}" + # + # self-hosted runners don't do this automatically; also useful to keep stuff around for debugging + # need to run sudo as the launch script and the container create root/other user owned files + - name: Clean up previous run + run: | + sudo podman ps -q --all --filter='ancestor=kstest-runner' | xargs -tr sudo podman rm -f + sudo podman volume rm --all || true + sudo rm -rf * .git + + - name: Clone repository + uses: actions/checkout@v4 + with: + ref: ${{ needs.pr-info.outputs.sha }} + path: kickstart-tests + + # - name: Rebase to current ${{ env.TARGET_BRANCH }} + # working-directory: ./kickstart-tests + # run: | + # git fetch origin + # git config user.name github-actions + # git config user.email github-actions@github.com + # git log --oneline -1 origin/${{ env.TARGET_BRANCH }} + # git rebase origin/${{ env.TARGET_BRANCH }} + # + + + - name: Get changed tests + working-directory: ./kickstart-tests + id: get_changed_tests + run: | + CHANGED_TESTS=$(git diff --name-only $TARGET_BRANCH ${{ needs.pr-info.outputs.sha }} -- *.ks.in $(find -maxdepth 1 -name '*.sh' -perm -u+x) | sed 's/\.ks\.in$//; s/\.sh$//' | sort -u) + echo "changed_tests=${CHANGED_TESTS}" + + + + # TODO: progress from anaconda