增加镜像扫描,通过评论触发 #31
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Process PR Comment and Run Script | |
on: | |
issue_comment: | |
types: [created] # 仅当评论被创建时触发 | |
jobs: | |
process_comment: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
- name: Make script executable | |
run: chmod +x ./.github/script/scan_image.sh | |
- name: Post a comment to the PR | |
run: | | |
echo ${{ github.repository }},${{ github.event.issue.number }} | |
curl -X POST \ | |
-H "Authorization: token ${{ secrets.OWNER_TOKEN }}" \ | |
-H "Accept: application/vnd.github.v3+json" \ | |
https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.issue.number }}/comments \ | |
-d '{"body": "开始镜像扫描"}' | |
- name: Check if comment has the specified prefix and run script | |
run: | | |
# 获取评论内容 | |
COMMENT_BODY="${{ github.event.comment.body }}" | |
PREFIX="扫描镜像:" | |
# 判断评论是否包含指定的前缀 | |
if [[ "$COMMENT_BODY" == "$PREFIX"* ]]; then | |
# 去掉前缀并提取后面的内容 | |
IMAGE_URL="${COMMENT_BODY#$PREFIX}" | |
echo $GITHUB_HEAD_REF ${{ github.event.issue.number }} ${{ secrets.CODEARTS_PASSWORD }} ${{ secrets.CODEARTS_SCAN_IMAGE_PIPELINE }} ${{ secrets.CODEARTS_ENDPOINT_ID }} $GIT_URL ${GITHUB_REPOSITORY%/*} ${GITHUB_REPOSITORY##*/} "$IMAGE_URL" | |
./.github/script/scan_image.sh $GITHUB_HEAD_REF ${{ github.event.issue.number }} ${{ secrets.CODEARTS_PASSWORD }} ${{ secrets.CODEARTS_SCAN_IMAGE_PIPELINE }} ${{ secrets.CODEARTS_ENDPOINT_ID }} $GIT_URL ${GITHUB_REPOSITORY%/*} ${GITHUB_REPOSITORY##*/} "$IMAGE_URL" | |
else | |
echo "Comment does not match the prefix, skipping the script execution." | |
fi |