github.com/oam-dev/kubevela@v1.9.11/.github/workflows/issue-commands.yml (about) 1 name: Run commands for issues and pull requests 2 on: 3 issues: 4 types: [labeled, opened] 5 issue_comment: 6 types: [created] 7 8 permissions: 9 contents: read 10 issues: write 11 12 jobs: 13 bot: 14 runs-on: ubuntu-22.04 15 permissions: 16 pull-requests: write 17 issues: write 18 steps: 19 - name: Checkout Actions 20 uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 21 with: 22 repository: "oam-dev/kubevela-github-actions" 23 path: ./actions 24 ref: v0.4.2 25 - name: Setup Node.js 26 uses: actions/setup-node@8f152de45cc393bb48ce5d89d36b731f54556e65 27 with: 28 node-version: '14' 29 cache: 'npm' 30 cache-dependency-path: ./actions/package-lock.json 31 - name: Install Dependencies 32 run: npm ci --production --prefix ./actions 33 - name: Run Commands 34 uses: ./actions/commands 35 with: 36 token: ${{ secrets.GITHUB_TOKEN }} 37 configPath: issue-commands 38 39 backport: 40 runs-on: ubuntu-22.04 41 if: github.event.issue.pull_request && contains(github.event.comment.body, '/backport') 42 permissions: 43 contents: write 44 pull-requests: write 45 issues: write 46 steps: 47 - name: Extract Command 48 id: command 49 uses: xt0rted/slash-command-action@bf51f8f5f4ea3d58abc7eca58f77104182b23e88 50 with: 51 repo-token: ${{ secrets.VELA_BOT_TOKEN }} 52 command: backport 53 reaction: "true" 54 reaction-type: "eyes" 55 allow-edits: "false" 56 permission-level: read 57 - name: Handle Command 58 uses: actions/github-script@d7906e4ad0b1822421a7e6a35d5ca353c962f410 59 env: 60 VERSION: ${{ steps.command.outputs.command-arguments }} 61 with: 62 github-token: ${{ secrets.GITHUB_TOKEN }} 63 script: | 64 const version = process.env.VERSION 65 let label = "backport release-" + version 66 if (version.includes("release")) { 67 label = "backport " + version 68 } 69 // Add our backport label. 70 github.rest.issues.addLabels({ 71 // Every pull request is an issue, but not every issue is a pull request. 72 issue_number: context.issue.number, 73 owner: context.repo.owner, 74 repo: context.repo.repo, 75 labels: [label] 76 }) 77 console.log("Added '" + label + "' label.") 78 - name: Checkout 79 uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 80 with: 81 fetch-depth: 0 82 - name: Open Backport PR 83 uses: zeebe-io/backport-action@08bafb375e6e9a9a2b53a744b987e5d81a133191 84 with: 85 github_token: ${{ secrets.GITHUB_TOKEN }} 86 github_workspace: ${{ github.workspace }} 87 88 retest: 89 runs-on: ubuntu-22.04 90 if: github.event.issue.pull_request && contains(github.event.comment.body, '/retest') 91 permissions: 92 actions: write 93 pull-requests: write 94 issues: write 95 steps: 96 - name: Retest the current pull request 97 uses: actions/github-script@d7906e4ad0b1822421a7e6a35d5ca353c962f410 98 env: 99 PULL_REQUEST_ID: ${{ github.event.issue.number }} 100 COMMENT_ID: ${{ github.event.comment.id }} 101 COMMENT_BODY: ${{ github.event.comment.body }} 102 with: 103 github-token: ${{ secrets.GITHUB_TOKEN }} 104 script: | 105 const pull_request_id = process.env.PULL_REQUEST_ID 106 const comment_id = process.env.COMMENT_ID 107 const comment_body = process.env.COMMENT_BODY 108 console.log("retest pr: #" + pull_request_id + " comment: " + comment_body) 109 const {data: pr} = await github.rest.pulls.get({ 110 owner: context.repo.owner, 111 repo: context.repo.repo, 112 pull_number: pull_request_id, 113 }) 114 console.log("pr: " + JSON.stringify(pr)) 115 const action = comment_body.split(" ")[0] 116 let workflow_ids = comment_body.split(" ").slice(1).filter(line => line.length > 0).map(line => line + ".yml") 117 if (workflow_ids.length == 0) workflow_ids = ["go.yml", "unit-test.yml", "e2e-test.yml", "e2e-multicluster-test.yml"] 118 for (let i = 0; i < workflow_ids.length; i++) { 119 const workflow_id = workflow_ids[i] 120 const {data: runs} = await github.rest.actions.listWorkflowRuns({ 121 owner: context.repo.owner, 122 repo: context.repo.repo, 123 workflow_id: workflow_id, 124 head_sha: pr.head.sha, 125 }) 126 console.log("runs for " + workflow_id + ": ", JSON.stringify(runs)) 127 runs.workflow_runs.forEach((workflow_run) => { 128 if (workflow_run.status === "in_progress") return 129 let handler = github.rest.actions.reRunWorkflow 130 if (action === "/retest-failed") handler = github.rest.actions.reRunWorkflowFailedJobs 131 handler({ 132 owner: context.repo.owner, 133 repo: context.repo.repo, 134 run_id: workflow_run.id 135 }) 136 }) 137 } 138 github.rest.reactions.createForIssueComment({ 139 owner: context.repo.owner, 140 repo: context.repo.repo, 141 comment_id: comment_id, 142 content: "eyes", 143 });