Skip to content

PR Manual Component testing #980

PR Manual Component testing

PR Manual Component testing #980

#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
name: PR Manual Component testing
on:
issue_comment:
types: [created]
permissions:
contents: read
jobs:
pr_commented:
name: PR comment
if: ${{ github.repository == 'apache/camel' && github.event.issue.pull_request && (github.event.comment.author_association == 'MEMBER' || github.event.comment.author_association == 'OWNER' || github.event.comment.author_association == 'CONTRIBUTOR') && startsWith(github.event.comment.body, '/component-test') }}
permissions:
pull-requests: write # to comment on a pull request
actions: read # to download artifact
runs-on: ubuntu-latest
strategy:
matrix:
java: [ '21' ]
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
submodules: recursive
- name: Check Permission
uses: actions-cool/check-user-permission@c21884f3dda18dafc2f8b402fe807ccc9ec1aa5e
- name: Retrieve sha
id: pr
env:
PR_NUMBER: ${{ github.event.issue.number }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_REPO: ${{ github.repository }}
COMMENT_AT: ${{ github.event.comment.created_at }}
run: |
pr="$(gh api /repos/${GH_REPO}/pulls/${PR_NUMBER})"
head_sha="$(echo "$pr" | jq -r .head.sha)"
# Check that the PR branch was not pushed to after the comment was created.
# Use the head commit date (not head.repo.pushed_at which is repo-level
# and changes whenever any branch is pushed, causing false negatives).
commit="$(gh api /repos/${GH_REPO}/commits/${head_sha})"
committed_at="$(echo "$commit" | jq -r .commit.committer.date)"
if [[ $(date -d "$committed_at" +%s) -gt $(date -d "$COMMENT_AT" +%s) ]]; then
echo "PR branch was updated after the comment was posted (commit: $committed_at, comment: $COMMENT_AT). Aborting."
exit 1
fi
echo "pr_sha=$head_sha" >> $GITHUB_OUTPUT
- name: React to comment
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_REPO: ${{ github.repository }}
run: |
gh api /repos/${GH_REPO}/issues/comments/${{ github.event.comment.id }}/reactions -f content="+1"
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
ref: ${{ steps.pr.outputs.pr_sha }}
submodules: recursive
- id: install-packages
uses: ./.github/actions/install-packages
- name: Set up JDK ${{ matrix.java }}
uses: actions/setup-java@be666c2fcd27ec809703dec50e508c2fdc7f6654 # v5.2.0
with:
distribution: 'temurin'
java-version: ${{ matrix.java }}
cache: 'maven'
- id: test
env:
comment_body: ${{ github.event.comment.body }}
name: Component test execution
uses: ./.github/actions/component-test
with:
run-id: ${{ github.run_id }}
pr-id: ${{ github.event.issue.number }}
comment-id: ${{ github.event.comment.id }}
comment-body: ${{ env.comment_body }}
artifact-upload-suffix: java-${{ matrix.java }}
- name: Post failure comment
if: failure() && steps.test.outcome != 'failure'
uses: peter-evans/create-or-update-comment@e8674b075228eee787fea43ef493e45ece1004c9 # v5.0.0
with:
issue-number: ${{ github.event.issue.number }}
body: |
:x: The `/component-test` run failed. Please [check the logs](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}) for details.