diff --git a/.github/markdown-templates/dep-bump.md b/.github/markdown-templates/dep-bump.md new file mode 100644 index 0000000000..58e99fb200 --- /dev/null +++ b/.github/markdown-templates/dep-bump.md @@ -0,0 +1,15 @@ +:coffee: *An Automated Dependency Version Bump PR* :crown: + +### Initial Changes + +The initial changes contained in this PR were produced by `go get`ing the dependency. + +``` +$ cd ./go +$ go get -u github.com/dolthub//go@ +``` + +### Before Merging + +This PR must have passing CI and a review before merging. + diff --git a/.github/workflows/bump-dependency.yaml b/.github/workflows/bump-dependency.yaml new file mode 100644 index 0000000000..2206663066 --- /dev/null +++ b/.github/workflows/bump-dependency.yaml @@ -0,0 +1,164 @@ +name: Bump Deps + +on: + repository_dispatch: + types: [ bump-dependency ] + +jobs: + get-label: + name: Get Label + outputs: + label: ${{ steps.get-label.outputs.label }} + runs-on: ubuntu-18.04 + steps: + - name: Get Label + id: get-label + env: + REPO: ${{ github.event.client_payload.dependency }} + run: | + if [ "$REPO" == "go-mysql-server" ] + then + echo "::set-output name=label::gms-bump" + else + echo "$REPO is unsupported" + exit 1 + fi + + stale-bump-prs: + name: Retrieving Stale Bump PRs + needs: get-label + outputs: + stale-pulls: ${{ steps.get-stale-prs.outputs.open-pulls }} + runs-on: ubuntu-18.04 + steps: + - name: Get Open Bump PRs + id: get-stale-prs + uses: actions/github-script@v4 + env: + LABEL: ${{ needs.get-label.outputs.label }} + with: + debug: true + github-token: ${{ secrets.REPO_ACCESS_TOKEN }} + script: | + try { + const { LABEL } = process.env; + const { owner, repo } = context.repo; + const res = await github.pulls.list({ + owner, + repo, + state: 'open', + sort: 'created', + direction: 'desc', + }); + + const { data } = res; + const filtered = data.filter(p => { + if (p.labels.length < 1) return false; + for (const label of p.labels) { + if (label.name === LABEL) return true; + } + return false; + }); + + console.log(filtered); + if (filtered.length > 0) core.setOutput("open-pulls", JSON.stringify(filtered)); + process.exit(0); + } catch(err) { + console.log("Error:", err); + process.exit(1); + } + + open-bump-pr: + needs: [get-label, stale-bump-prs] + name: Open Bump PR + runs-on: ubuntu-18.04 + outputs: + latest-pr: ${{ steps.latest-pr.outputs.pr_url }} + steps: + - uses: actions/checkout@v2 + - name: Bump dependency + working-directory: go + run: go get -u github.com/dolthub/${{ github.event.client_payload.dependency }}/go@${{ github.event.client_payload.head_commit_sha }} + - name: Get Assignee and Reviewer + id: get_reviewer + run: | + if [ "${{ github.event.client_payload.assignee }}" == "zachmu" ] + then + echo "::set-output name=reviewer::Hydrocharged" + else + echo "::set-output name=reviewer::zachmu" + fi + - name: Get short hash + id: short-sha + run: | + commit=${{ github.event.client_payload.head_commit_sha }} + short=${commit:0:8} + echo "::set-output name=short::$short" + - name: Create and Push new branch + run: | + git config --global --add user.name "${{ github.event.client_payload.assignee }}" + git config --global --add user.email "${{ github.event.client_payload.assignee_email }}" + branchname=${{ format('{0}-{1}', github.event.client_payload.assignee, steps.short-sha.outputs.short) }} + git checkout -b "$branchname" + git add . + git commit -m "${{ format('[ga-bump-dep] Bump dependency in Dolt by {0}', github.event.client_payload.assignee) }}" + git push origin "$branchname" + - name: pull-request + uses: repo-sync/pull-request@v2 + id: latest-pr + with: + source_branch: ${{ format('{0}-{1}', github.event.client_payload.assignee, steps.short-sha.outputs.short ) }} + destination_branch: "master" + github_token: ${{ secrets.REPO_ACCESS_TOKEN }} + pr_title: "[auto-bump] dependency by ${{ github.event.client_payload.assignee }}" + pr_template: ".github/markdown-templates/dep-bump.md" + pr_reviewer: ${{ steps.get_reviewer.outputs.reviewer }} + pr_assignee: ${{ github.event.client_payload.assignee }} + pr_label: ${{ needs.get-label.outputs.label }} + + comment-on-stale-prs: + needs: [open-bump-pr, stale-bump-prs] + if: ${{ needs.stale-bump-prs.outputs.stale-pulls != '' }} + runs-on: ubuntu-18.04 + strategy: + matrix: + pull: ${{ fromJson(needs.stale-bump-prs.outputs.stale-pulls) }} + steps: + - name: Comment/Close Stale PRs + id: get-stale-prs + uses: actions/github-script@v4 + env: + PULL: ${{ toJson(matrix.pull) }} + SUPERSEDED_BY: ${{ needs.open-bump-pr.outputs.latest-pr }} + with: + debug: true + github-token: ${{ secrets.REPO_ACCESS_TOKEN }} + script: | + try { + const { owner, repo } = context.repo; + const { PULL, SUPERSEDED_BY } = process.env; + const pull = JSON.parse(PULL); + + for (const label of pull.labels) { + if (label.name === "go-tests-ok") { + await github.issues.createComment({ + issue_number: pull.number, + owner, + repo, + body: `This PR has been superseded by ${SUPERSEDED_BY}` + }); + await github.pulls.update({ + owner, + repo, + pull_number: pull.number, + state: 'closed', + }); + break; + } + } + + process.exit(0); + } catch(err) { + console.log("Error:", err); + process.exit(1); + }