From 3e972418a97a8d638b27370f9f8614a95e5b1a2d Mon Sep 17 00:00:00 2001 From: Yang Chiu Date: Wed, 7 Sep 2022 14:42:10 +0800 Subject: [PATCH] ci: add github action for backport and automation issues Signed-off-by: Yang Chiu --- .github/workflows/close-issue.yml | 50 ++++++++++++++++ .github/workflows/create-issue.yml | 94 ++++++++++++++++++++++++++++++ 2 files changed, 144 insertions(+) create mode 100644 .github/workflows/close-issue.yml create mode 100644 .github/workflows/create-issue.yml diff --git a/.github/workflows/close-issue.yml b/.github/workflows/close-issue.yml new file mode 100644 index 0000000..053c068 --- /dev/null +++ b/.github/workflows/close-issue.yml @@ -0,0 +1,50 @@ +name: Close-Issue +on: + issues: + types: [unlabeled] +jobs: + backport: + runs-on: ubuntu-latest + if: contains(github.event.label.name, 'backport-needed') + steps: + - name: Get Backport Version + uses: xom9ikk/split@v1 + id: split + with: + string: ${{ github.event.label.name }} + separator: / + - name: Check if Backport Issue Exists + uses: actions-cool/issues-helper@v3 + id: if-backport-issue-exists + with: + actions: 'find-issues' + token: ${{ github.token }} + title-includes: | + [BACKPORT][v${{ steps.split.outputs._1 }}]${{ github.event.issue.title }} + - name: Close Backport Issue + if: fromJSON(steps.if-backport-issue-exists.outputs.issues)[0] != null + uses: actions-cool/issues-helper@v3 + with: + actions: 'close-issue' + token: ${{ github.token }} + issue-number: ${{ fromJSON(steps.if-backport-issue-exists.outputs.issues)[0].number }} + + automation: + runs-on: ubuntu-latest + if: contains(github.event.label.name, 'require/automation-e2e') + steps: + - name: Check if Automation Issue Exists + uses: actions-cool/issues-helper@v3 + id: if-automation-issue-exists + with: + actions: 'find-issues' + token: ${{ github.token }} + title-includes: | + [TEST]${{ github.event.issue.title }} + - name: Close Automation Test Issue + if: fromJSON(steps.if-automation-issue-exists.outputs.issues)[0] != null + uses: actions-cool/issues-helper@v3 + with: + actions: 'close-issue' + token: ${{ github.token }} + issue-number: ${{ fromJSON(steps.if-automation-issue-exists.outputs.issues)[0].number }} diff --git a/.github/workflows/create-issue.yml b/.github/workflows/create-issue.yml new file mode 100644 index 0000000..2321107 --- /dev/null +++ b/.github/workflows/create-issue.yml @@ -0,0 +1,94 @@ +name: Create-Issue +on: + issues: + types: [labeled] +jobs: + backport: + runs-on: ubuntu-latest + if: contains(github.event.label.name, 'backport-needed') + steps: + - name: Get Backport Version + uses: xom9ikk/split@v1 + id: split + with: + string: ${{ github.event.label.name }} + separator: / + - name: Check if Backport Issue Exists + uses: actions-cool/issues-helper@v3 + id: if-backport-issue-exists + with: + actions: 'find-issues' + token: ${{ github.token }} + issue-state: 'all' + title-includes: | + [BACKPORT][v${{ steps.split.outputs._1 }}]${{ github.event.issue.title }} + - name: Get Milestone Object + if: fromJSON(steps.if-backport-issue-exists.outputs.issues)[0] == null + uses: longhorn/bot/milestone-action@master + id: milestone + with: + token: ${{ github.token }} + repository: ${{ github.repository }} + milestone_name: v${{ steps.split.outputs._1 }} + - name: Get Labels + if: fromJSON(steps.if-backport-issue-exists.outputs.issues)[0] == null + id: labels + run: | + RAW_LABELS="${{ join(github.event.issue.labels.*.name, ' ') }}" + echo "RAW LABELS: $RAW_LABELS" + LABELS=$(echo "$RAW_LABELS" | sed -r 's/\s*backport-needed\S+//g' | sed -r 's/\s*require\/automation-e2e//g' | xargs | sed 's/ /, /g') + echo "LABELS: $LABELS" + echo "::set-output name=labels::$LABELS" + - name: Create Backport Issue + if: fromJSON(steps.if-backport-issue-exists.outputs.issues)[0] == null + uses: dacbd/create-issue-action@v1 + id: new-issue + with: + token: ${{ github.token }} + title: | + [BACKPORT][v${{ steps.split.outputs._1 }}]${{ github.event.issue.title }} + body: | + backport ${{ github.event.issue.html_url }} + labels: ${{ steps.labels.outputs.labels }} + milestone: ${{ fromJSON(steps.milestone.outputs.data).number }} + assignees: ${{ join(github.event.issue.assignees.*.login, ', ') }} + - name: Get Repo Id + if: fromJSON(steps.if-backport-issue-exists.outputs.issues)[0] == null + uses: octokit/request-action@v2.x + id: repo + with: + route: GET /repos/${{ github.repository }} + env: + GITHUB_TOKEN: ${{ github.token }} + - name: Add Backport Issue To Release + if: fromJSON(steps.if-backport-issue-exists.outputs.issues)[0] == null + uses: longhorn/bot/add-zenhub-release-action@master + with: + zenhub_token: ${{ secrets.ZENHUB_TOKEN }} + repo_id: ${{ fromJSON(steps.repo.outputs.data).id }} + issue_number: ${{ steps.new-issue.outputs.number }} + release_name: ${{ steps.split.outputs._1 }} + + automation: + runs-on: ubuntu-latest + if: contains(github.event.label.name, 'require/automation-e2e') + steps: + - name: Check if Automation Issue Exists + uses: actions-cool/issues-helper@v3 + id: if-automation-issue-exists + with: + actions: 'find-issues' + token: ${{ github.token }} + issue-state: 'all' + title-includes: | + [TEST]${{ github.event.issue.title }} + - name: Create Automation Test Issue + if: fromJSON(steps.if-automation-issue-exists.outputs.issues)[0] == null + uses: dacbd/create-issue-action@v1 + with: + token: ${{ github.token }} + title: | + [TEST]${{ github.event.issue.title }} + body: | + adding/updating auto e2e test cases for ${{ github.event.issue.html_url }} if they can be automated + assignees: ${{ join(github.event.issue.assignees.*.login, ', ') }} \ No newline at end of file