bump-dependency #455
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: Bump Deps | |
on: | |
repository_dispatch: | |
types: [ bump-dependency ] | |
jobs: | |
get-label: | |
name: Get Label | |
outputs: | |
label: ${{ steps.get-label.outputs.label }} | |
runs-on: ubuntu-22.04 | |
steps: | |
- name: Get Label | |
id: get-label | |
env: | |
REPO: ${{ github.event.client_payload.dependency }} | |
run: | | |
if [ "$REPO" == "dolt" ] | |
then | |
echo "label=dolt-bump" >> $GITHUB_OUTPUT | |
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-22.04 | |
steps: | |
- name: Get Open Bump PRs | |
id: get-stale-prs | |
uses: actions/github-script@v7 | |
env: | |
LABEL: ${{ needs.get-label.outputs.label }} | |
with: | |
debug: true | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
script: | | |
try { | |
const { LABEL } = process.env; | |
const { owner, repo } = context.repo; | |
const res = await github.rest.pulls.list({ | |
owner, | |
repo, | |
state: 'open', | |
sort: 'created', | |
direction: 'desc', | |
}); | |
const { data } = res; | |
const reduced = data.reduce((acc, p) => { | |
if (p.labels.length < 1) return acc; | |
let keepAlive = false; | |
let shouldPush = false; | |
for (const label of p.labels) { | |
if (label.name === LABEL) { | |
shouldPush = true; | |
} | |
if (label.name === "keep-alive") { | |
keepAlive = true; | |
} | |
} | |
if (shouldPush) { | |
acc.push({ | |
number: p.number, | |
keepAlive, | |
headRef: p.head.ref, | |
}); | |
} | |
return acc; | |
}, []); | |
console.log(reduced); | |
if (reduced.length > 0) core.setOutput("open-pulls", JSON.stringify(reduced)); | |
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-22.04 | |
outputs: | |
latest-pr: ${{ steps.latest-pr.outputs.pr_url }} | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
- name: Set up Go 1.x | |
uses: actions/setup-go@v5 | |
with: | |
go-version-file: go.mod | |
- name: Bump dependency | |
run: | | |
go get github.com/dolthub/${{ github.event.client_payload.dependency }}/go@${{ github.event.client_payload.head_commit_sha }} | |
go mod tidy | |
- name: Get short hash | |
id: short-sha | |
run: | | |
commit=${{ github.event.client_payload.head_commit_sha }} | |
short=${commit:0:8} | |
echo "short=$short" >> $GITHUB_OUTPUT | |
- name: Get Assignee and Reviewer | |
id: get_reviewer | |
run: | | |
if [ "${{ contains(github.event.client_payload.assignee, 'github-actions[bot]') }}" == "true" ] | |
then | |
echo "assignee=zachmu" >> $GITHUB_OUTPUT | |
else | |
assignee="${{ github.event.client_payload.assignee }}" | |
echo "assignee=$assignee" >> $GITHUB_OUTPUT | |
fi | |
if [ "${{ github.event.client_payload.assignee }}" == "zachmu" ] | |
then | |
echo "reviewer=Hydrocharged" >> $GITHUB_OUTPUT | |
else | |
echo "reviewer=zachmu" >> $GITHUB_OUTPUT | |
fi | |
- name: Create and Push new branch | |
run: | | |
git config --global --add user.name "${{ steps.get_reviewer.outputs.assignee }}" | |
git config --global --add user.email "${{ github.event.client_payload.assignee_email }}" | |
branchname=${{ format('{0}-{1}', steps.get_reviewer.outputs.assignee, steps.short-sha.outputs.short) }} | |
git checkout -b "$branchname" | |
git add . | |
git commit -m "${{ format('[ga-bump-dep] Bump dependency in Doltgres by {0}', steps.get_reviewer.outputs.assignee) }}" | |
git push origin "$branchname" | |
- name: pull-request | |
uses: repo-sync/pull-request@v2 | |
id: latest-pr | |
with: | |
source_branch: ${{ format('{0}-{1}', steps.get_reviewer.outputs.assignee, steps.short-sha.outputs.short ) }} | |
destination_branch: "main" | |
github_token: ${{ secrets.PUBLIC_REPO_ACCESS_TOKEN || secrets.REPO_ACCESS_TOKEN || secrets.GITHUB_TOKEN }} | |
pr_title: "[auto-bump] [no-release-notes] dependency by ${{ steps.get_reviewer.outputs.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-22.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@v7 | |
env: | |
PULL: ${{ toJson(matrix.pull) }} | |
SUPERSEDED_BY: ${{ needs.open-bump-pr.outputs.latest-pr }} | |
with: | |
debug: true | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
script: | | |
try { | |
const { owner, repo } = context.repo; | |
const { PULL, SUPERSEDED_BY } = process.env; | |
const pull = JSON.parse(PULL); | |
if (pull.keepAlive) process.exit(0); | |
console.log(`Closing open pr ${pull.number}`); | |
await github.rest.issues.createComment({ | |
issue_number: pull.number, | |
owner, | |
repo, | |
body: `This PR has been superseded by ${SUPERSEDED_BY}` | |
}); | |
await github.rest.pulls.update({ | |
owner, | |
repo, | |
pull_number: pull.number, | |
state: 'closed', | |
}); | |
process.exit(0); | |
} catch(err) { | |
console.log("Error:", err); | |
process.exit(1); | |
} |