mirror of
https://github.com/dolthub/dolt.git
synced 2026-01-06 08:50:04 -06:00
215 lines
7.0 KiB
YAML
215 lines
7.0 KiB
YAML
name: Bump Deps
|
|
|
|
on:
|
|
repository_dispatch:
|
|
types: [ bump-dependency ]
|
|
|
|
jobs:
|
|
auth:
|
|
name: Authenticate Caller
|
|
runs-on: ubuntu-22.04
|
|
steps:
|
|
- name: Check client token
|
|
env:
|
|
PAYLOAD_TOKEN: ${{ github.event.client_payload.token }}
|
|
EXPECTED_TOKEN: ${{ secrets.CLIENT_AUTH_TOKEN }}
|
|
run: |
|
|
set -euo pipefail
|
|
# refuse to proceed without a token
|
|
if [ -z "${PAYLOAD_TOKEN:-}" ]; then
|
|
echo "Unauthorized: missing token"
|
|
exit 1
|
|
fi
|
|
# simple equality check; doesn't echo secrets
|
|
if [ "${PAYLOAD_TOKEN}" != "${EXPECTED_TOKEN}" ]; then
|
|
echo "Unauthorized: bad token"
|
|
exit 1
|
|
fi
|
|
echo "Caller authenticated"
|
|
|
|
get-label:
|
|
needs: auth
|
|
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" == "go-mysql-server" ]
|
|
then
|
|
echo "label=gms-bump" >> $GITHUB_OUTPUT
|
|
elif [ "$REPO" == "eventsapi_schema" ]
|
|
then
|
|
echo "label=eventsapi_schema-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.REPO_ACCESS_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.REPO_ACCESS_TOKEN || secrets.GITHUB_TOKEN }}
|
|
- name: Set up Go 1.x
|
|
uses: actions/setup-go@v5
|
|
with:
|
|
go-version-file: go/go.mod
|
|
- name: Bump dependency
|
|
working-directory: go
|
|
run: |
|
|
go get github.com/dolthub/${{ github.event.client_payload.dependency }}@${{ github.event.client_payload.head_commit_sha }}
|
|
go mod tidy
|
|
- name: Get Assignee and Reviewer
|
|
id: get_reviewer
|
|
run: |
|
|
if [ "${{ github.event.client_payload.assignee }}" == "zachmu" ]
|
|
then
|
|
echo "reviewer=Hydrocharged" >> $GITHUB_OUTPUT
|
|
else
|
|
echo "reviewer=zachmu" >> $GITHUB_OUTPUT
|
|
fi
|
|
- 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: 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: "main"
|
|
github_token: ${{ secrets.REPO_ACCESS_TOKEN }}
|
|
pr_title: "[auto-bump] [no-release-notes] 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-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.REPO_ACCESS_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);
|
|
}
|