github.com/dolthub/go-mysql-server@v0.18.0/.github/workflows/bump-dependency.yaml (about)

     1  name: Bump Deps
     2  
     3  on:
     4    repository_dispatch:
     5      types: [ bump-dependency ]
     6  
     7  jobs:
     8    get-label:
     9      name: Get Label
    10      outputs:
    11        label: ${{ steps.get-label.outputs.label }}
    12      runs-on: ubuntu-22.04
    13      steps:
    14        - name: Get Label
    15          id: get-label
    16          env:
    17            REPO: ${{ github.event.client_payload.dependency }}
    18          run: |
    19            if [ "$REPO" == "vitess" ]
    20            then
    21              echo "label=vitess-bump" >> $GITHUB_OUTPUT
    22            else
    23              echo "$REPO is unsupported"
    24              exit 1
    25            fi
    26  
    27    stale-bump-prs:
    28      name: Retrieving Stale Bump PRs
    29      needs: get-label
    30      outputs:
    31        stale-pulls: ${{ steps.get-stale-prs.outputs.open-pulls }}
    32      runs-on: ubuntu-22.04
    33      steps:
    34        - name: Get Open Bump PRs
    35          id: get-stale-prs
    36          uses: actions/github-script@v6
    37          env:
    38            LABEL: ${{ needs.get-label.outputs.label }}
    39          with:
    40            debug: true
    41            github-token: ${{ secrets.REPO_ACCESS_TOKEN }}
    42            script: |
    43              try {
    44                const { LABEL } = process.env;
    45                const { owner, repo } = context.repo;
    46                const res = await github.rest.pulls.list({
    47                  owner,
    48                  repo,
    49                  state: 'open',
    50                  sort: 'created',
    51                  direction: 'desc',
    52                });
    53  
    54                const { data } = res;
    55                const reduced = data.reduce((acc, p) => {
    56                  if (p.labels.length < 1) return acc;
    57  
    58                  let keepAlive = false;
    59                  let shouldPush = false;
    60  
    61                  for (const label of p.labels) {
    62                    if (label.name === LABEL) {
    63                      shouldPush = true;
    64                    }
    65                    if (label.name === "keep-alive") {
    66                      keepAlive = true;
    67                    }
    68                  }
    69                  if (shouldPush) {
    70                    acc.push({
    71                      number: p.number,
    72                      keepAlive,
    73                      headRef: p.head.ref,
    74                    });
    75                  }
    76                  return acc;
    77                }, []);
    78  
    79                console.log(reduced);
    80                if (reduced.length > 0) core.setOutput("open-pulls", JSON.stringify(reduced));
    81                process.exit(0);
    82              } catch(err) {
    83                console.log("Error:", err);
    84                process.exit(1);
    85              }
    86  
    87    open-bump-pr:
    88      needs: [get-label, stale-bump-prs]
    89      name: Open Bump PR
    90      runs-on: ubuntu-22.04
    91      outputs:
    92        latest-pr: ${{ steps.latest-pr.outputs.pr_url }}
    93      steps:
    94        - uses: actions/checkout@v3
    95          with:
    96            token: ${{ secrets.REPO_ACCESS_TOKEN || secrets.GITHUB_TOKEN }}
    97        - name: Set up Go 1.x
    98          uses: actions/setup-go@v3
    99          with:
   100            go-version: 1.19
   101        - name: Bump dependency
   102          run: GOOS=linux go get github.com/dolthub/${{ github.event.client_payload.dependency }}@${{ github.event.client_payload.head_commit_sha }}
   103        - name: Get Assignee and Reviewer
   104          id: get_reviewer
   105          run: |
   106            if [ "${{ github.event.client_payload.assignee }}" == "zachmu" ]
   107            then
   108              echo "reviewer=Hydrocharged" >> $GITHUB_OUTPUT
   109            else
   110              echo "reviewer=zachmu" >> $GITHUB_OUTPUT
   111            fi
   112        - name: Get short hash
   113          id: short-sha
   114          run: |
   115            commit=${{ github.event.client_payload.head_commit_sha }}
   116            short=${commit:0:8}
   117            echo "short=$short" >> $GITHUB_OUTPUT
   118        - name: Create and Push new branch
   119          run: |
   120            git config --global --add user.name "${{ github.event.client_payload.assignee }}"
   121            git config --global --add user.email "${{ github.event.client_payload.assignee_email }}"
   122            branchname=${{ format('{0}-{1}', github.event.client_payload.assignee, steps.short-sha.outputs.short) }}
   123            git checkout -b "$branchname"
   124            git add .
   125            git commit -m "${{ format('[ga-bump-dep] Bump dependency in GMS by {0}', github.event.client_payload.assignee) }}"
   126            git push origin "$branchname"
   127        - name: pull-request
   128          uses: repo-sync/pull-request@v2
   129          id: latest-pr
   130          with:
   131            source_branch: ${{ format('{0}-{1}', github.event.client_payload.assignee, steps.short-sha.outputs.short ) }}
   132            destination_branch: "main"
   133            github_token: ${{ secrets.REPO_ACCESS_TOKEN }}
   134            pr_title: "[auto-bump] [no-release-notes] dependency by ${{ github.event.client_payload.assignee }}"
   135            pr_template: ".github/markdown-templates/dep-bump.md"
   136            pr_reviewer: ${{ steps.get_reviewer.outputs.reviewer }}
   137            pr_assignee: ${{ github.event.client_payload.assignee }}
   138            pr_label: ${{ needs.get-label.outputs.label }}
   139  
   140    comment-on-stale-prs:
   141      needs: [open-bump-pr, stale-bump-prs]
   142      if: ${{ needs.stale-bump-prs.outputs.stale-pulls != '' }}
   143      runs-on: ubuntu-22.04
   144      strategy:
   145        matrix:
   146          pull: ${{ fromJson(needs.stale-bump-prs.outputs.stale-pulls) }}
   147      steps:
   148        - name: Comment/Close Stale PRs
   149          id: get-stale-prs
   150          uses: actions/github-script@v6
   151          env:
   152            PULL: ${{ toJson(matrix.pull) }}
   153            SUPERSEDED_BY: ${{ needs.open-bump-pr.outputs.latest-pr }}
   154          with:
   155            debug: true
   156            github-token: ${{ secrets.REPO_ACCESS_TOKEN }}
   157            script: |
   158              try {
   159                const { owner, repo } = context.repo;
   160                const { PULL, SUPERSEDED_BY } = process.env;
   161                const pull = JSON.parse(PULL);
   162  
   163                if (pull.keepAlive) process.exit(0);
   164  
   165                const checkSuiteRes = await github.rest.checks.listSuitesForRef({
   166                  owner,
   167                  repo,
   168                  ref: pull.headRef,
   169                });
   170  
   171                if (checkSuiteRes.data) {
   172                  for (const suite of checkSuiteRes.data.check_suites) {
   173                    console.log("suite id:", suite.id);
   174                    console.log("suite app slug:", suite.app.slug);
   175                    console.log("suite status:", suite.status);
   176                    console.log("suite conclusion:", suite.conclusion);
   177                    if (suite.app.slug === "github-actions") {
   178                       if (suite.status !== "completed" || suite.conclusion !== "success") {
   179                         console.log(`Leaving pr open due to status:${suite.status} conclusion${suite.conclusion}`);
   180                         process.exit(0);
   181                       }
   182                    }
   183                  }
   184  
   185                  console.log(`Closing open pr ${pull.number}`);
   186                  await github.rest.issues.createComment({
   187                    issue_number: pull.number,
   188                    owner,
   189                    repo,
   190                    body: `This PR has been superseded by ${SUPERSEDED_BY}`
   191                  });
   192  
   193                  await github.rest.pulls.update({
   194                    owner,
   195                    repo,
   196                    pull_number: pull.number,
   197                    state: 'closed',
   198                  });
   199                }
   200  
   201                process.exit(0);
   202              } catch(err) {
   203                console.log("Error:", err);
   204                process.exit(1);
   205              }