Skip to content

Commit

Permalink
DONT MERGE: test against current branch
Browse files Browse the repository at this point in the history
  • Loading branch information
KKoukiou committed May 15, 2024
1 parent 085e16c commit f2b3769
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 120 deletions.
67 changes: 7 additions & 60 deletions .github/workflows/kickstart-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@

name: kickstart-tests
on:
issue_comment:
types: [created]
pull_request:
types: [opened, reopened, synchronize]

permissions:
contents: read
Expand All @@ -42,24 +42,6 @@ jobs:
if: startsWith(github.event.comment.body, '/kickstart-test')
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
Expand All @@ -68,17 +50,6 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Parse comment arguments
id: parse_comment_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
ARGS=$(echo "$BODY" | sed -n '1 s/^[^ ]* *//p' | sed 's/[[:space:]]*$//')
echo "workflow arguments are: $ARGS"
echo "comment_args=${ARGS}" >> $GITHUB_OUTPUT
- name: Get timestamp
id: timestamp
run: echo "::set-output name=timestamp::$(date +'%Y-%m-%d_%H:%M:%S')"
Expand All @@ -89,22 +60,23 @@ jobs:
set -eux
# comment on PR
pr_num="${{ github.event.issue.number }}"
timestamp=${{ steps.teimstamp.outputs.timestamp }}
timestamp=${{ steps.timestamp.outputs.timestamp }}
sha="${{ steps.pr_api.outcome == 'success' && fromJson(steps.pr_api.outputs.data).head.sha }}"
echo "image_description=pr$pr_num-$timestamp-$sha" >> $GITHUB_OUTPUT
fi
outputs:
allowed_user: ${{ steps.check_user_perm.outputs.allowed_user }}
allowed_user: 'true'
base_ref: ${{ fromJson(steps.pr_api.outputs.data).base.ref }}
sha: ${{ fromJson(steps.pr_api.outputs.data).head.sha }}
comment_args: ${{ steps.parse_comment_args.outputs.comment_args }}
comment_args: '--testtype smoke'
target_branch: ${{ fromJson(steps.pr_api.outputs.data).base.ref }}
timestamp: ${{steps.kstest_run_description.outputs.image_description}}

run:
needs: pr-info
# only do this for Fedora for now; once we have RHEL 8/9 boot.iso builds working, also support these
if: needs.pr-info.outputs.allowed_user == 'true' && needs.pr-info.outputs.comment_args != '' && ! contains(github.event.comment.body, '--waive')
if: needs.pr-info.outputs.allowed_user == 'true' && needs.pr-info.outputs.comment_args != ''
runs-on: [self-hosted, kstest]
timeout-minutes: 300
env:
Expand Down Expand Up @@ -336,28 +308,3 @@ jobs:
target_url: 'https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

waive:
runs-on: ubuntu-latest
needs: pr-info
if: needs.pr-info.outputs.allowed_user == 'true' && contains(github.event.comment.body, '--waive')
steps:

- name: Get the waiving reason
id: get_reason
env:
BODY: ${{ github.event.comment.body }}
run: |
REASON=$(echo "$BODY" | sed -e "s#/kickstart-test --waive ##" | sed 's/[[:space:]]*$//')
echo "reason=Waived, $REASON" >> $GITHUB_OUTPUT
- name: Set status
uses: octokit/request-action@v2.x
with:
route: 'POST /repos/${{ github.repository }}/statuses/${{ needs.pr-info.outputs.sha }}'
context: 'kickstart-test --testtype smoke'
description: '${{ steps.get_reason.outputs.reason }}'
state: ${{ job.status }}
target_url: 'https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
65 changes: 5 additions & 60 deletions .github/workflows/kickstart-tests.yml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -24,36 +24,17 @@

name: kickstart-tests
on:
issue_comment:
types: [created]
pull_request:
types: [opened, reopened, synchronize]

permissions:
contents: read
statuses: write

jobs:
pr-info:
if: startsWith(github.event.comment.body, '/kickstart-test')
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
Expand All @@ -62,17 +43,6 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Parse comment arguments
id: parse_comment_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
ARGS=$(echo "$BODY" | sed -n '1 s/^[^ ]* *//p' | sed 's/[[:space:]]*$//')
echo "workflow arguments are: $ARGS"
echo "comment_args=${ARGS}" >> $GITHUB_OUTPUT

- name: Get timestamp
id: timestamp
run: echo "::set-output name=timestamp::$(date +'%Y-%m-%d_%H:%M:%S')"
Expand All @@ -89,17 +59,17 @@ jobs:
fi

outputs:
allowed_user: ${{ steps.check_user_perm.outputs.allowed_user }}
allowed_user: 'true'
base_ref: ${{ fromJson(steps.pr_api.outputs.data).base.ref }}
sha: ${{ fromJson(steps.pr_api.outputs.data).head.sha }}
comment_args: ${{ steps.parse_comment_args.outputs.comment_args }}
comment_args: '--testtype smoke'
target_branch: ${{ fromJson(steps.pr_api.outputs.data).base.ref }}
timestamp: ${{steps.kstest_run_description.outputs.image_description}}

run:
needs: pr-info
# only do this for Fedora for now; once we have RHEL 8/9 boot.iso builds working, also support these
if: needs.pr-info.outputs.allowed_user == 'true' && needs.pr-info.outputs.comment_args != '' && ! contains(github.event.comment.body, '--waive')
if: needs.pr-info.outputs.allowed_user == 'true' && needs.pr-info.outputs.comment_args != ''
runs-on: [self-hosted, kstest]
timeout-minutes: 300
env:
Expand Down Expand Up @@ -331,29 +301,4 @@ jobs:
target_url: 'https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

waive:
runs-on: ubuntu-latest
needs: pr-info
if: needs.pr-info.outputs.allowed_user == 'true' && contains(github.event.comment.body, '--waive')
steps:

- name: Get the waiving reason
id: get_reason
env:
BODY: ${{ github.event.comment.body }}
run: |
REASON=$(echo "$BODY" | sed -e "s#/kickstart-test --waive ##" | sed 's/[[:space:]]*$//')
echo "reason=Waived, $REASON" >> $GITHUB_OUTPUT

- name: Set status
uses: octokit/request-action@v2.x
with:
route: 'POST /repos/${{ github.repository }}/statuses/${{ needs.pr-info.outputs.sha }}'
context: 'kickstart-test --testtype smoke'
description: '${{ steps.get_reason.outputs.reason }}'
state: ${{ job.status }}
target_url: 'https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
{% endif %}

0 comments on commit f2b3769

Please sign in to comment.