Open-source document signature platform. Not affiliated with DocuSign.
TypeScript
Update workflow: ignore clashes in workflow files it keeps, honour the production branch
Claudefe4ab1554a1a
diff --git a/.github/workflows/update-signudoc.yml b/.github/workflows/update-signudoc.ymlindex f154f19..7c7f8e8 100644--- a/.github/workflows/update-signudoc.yml+++ b/.github/workflows/update-signudoc.yml@@ -26,6 +26,9 @@# run merge an update that applies cleanly straight into your production# branch instead of opening a pull request.#+# If Vercel deploys from a branch other than the default branch, set the+# repository variable SIGNUDOC_PRODUCTION_BRANCH to it.+## In the SignuDoc repository itself the job is skipped.name: Update SignuDoc@@ -71,12 +74,14 @@ jobs:REQUESTED_VERSION: ${{ inputs.version }}BASED_ON: ${{ inputs.based_on }}MERGE_NOW: ${{ inputs.merge == true || vars.SIGNUDOC_AUTO_MERGE == '1' }}- BASE_BRANCH: ${{ github.event.repository.default_branch }}+ # The branch Vercel deploys to production. Set the repository+ # variable SIGNUDOC_PRODUCTION_BRANCH if it is not the default branch.+ BASE_BRANCH: ${{ vars.SIGNUDOC_PRODUCTION_BRANCH || github.event.repository.default_branch }}steps:- uses: actions/checkout@v6with:fetch-depth: 0- ref: ${{ github.event.repository.default_branch }}+ ref: ${{ vars.SIGNUDOC_PRODUCTION_BRANCH || github.event.repository.default_branch }}token: ${{ secrets.SIGNUDOC_UPDATE_TOKEN || github.token }}- name: Merge the release into a branch@@ -235,13 +240,20 @@ jobs:--merge-base="$base" HEAD "$target")merge_status=$?set -e- if [ "$merge_status" -eq 1 ]; then+ clashes=$(tail -n +2 <<< "$merge_output" | sed '/^$/d')+ # Workflow files are settled separately below when they are+ # kept as they are (no token) or merged from where an earlier+ # run left them, so a clash there does not stop the update.+ if [ "$HAS_UPDATE_TOKEN" != "true" ] || [ "$wf_base" != "$base" ]; then+ clashes=$(grep -v '^\.github/workflows/' <<< "$clashes" || true)+ fi+ if [ "$merge_status" -eq 1 ] && [ -n "$clashes" ]; thensummary "## SignuDoc $tag clashes with changes in this repository" "" \"These files were changed both here and in SignuDoc, in the same places:" ""- tail -n +2 <<< "$merge_output" | sed '/^$/d; s/^/- `/; s/$/`/' >> "$GITHUB_STEP_SUMMARY"+ sed 's/^/- `/; s/$/`/' <<< "$clashes" >> "$GITHUB_STEP_SUMMARY"summary "" "To update by hand, see \"Keep your install up to date\" in docs/self-hosting.md. Use \`${base}\` as the SignuDoc commit this repository is based on."stop "SignuDoc $tag clashes with this repository's own changes. See the run summary."- elif [ "$merge_status" -ne 0 ]; then+ elif [ "$merge_status" -gt 1 ]; thenstop "git could not merge SignuDoc $tag."fimerged_tree=$(head -n 1 <<< "$merge_output")diff --git a/docs/self-hosting.md b/docs/self-hosting.mdindex c26078e..69a46a0 100644--- a/docs/self-hosting.md+++ b/docs/self-hosting.md@@ -91,6 +91,8 @@ Two optional settings in your repository on GitHub:To skip the pull request, run the workflow with **Merge straight into the production branch** ticked, or set the repository variable `SIGNUDOC_AUTO_MERGE` to `1` to have the weekly run do that. It only does so when the release merges cleanly. Vercel then deploys the update without anyone looking at it first.+If Vercel deploys your site from a branch other than the repository's default branch, set the repository variable `SIGNUDOC_PRODUCTION_BRANCH` to that branch, so the workflow updates and opens pull requests against it.+**A copy made before version 0.2.0** does not have the workflow yet. Add it once: in your repository on GitHub choose **Add file**, **Create new file**, name it `.github/workflows/update-signudoc.yml`, paste in [the workflow](https://raw.githubusercontent.com/NYLLON-SOFTWARE/SignuDoc/main/.github/workflows/update-signudoc.yml), and commit it to your production branch. Settings in SignuDoc links to the right page. Then run it as above.**Updating by hand.** A copy made by the Deploy button has none of this project's history, so a plain `git merge` refuses to merge "unrelated histories". Tell git which SignuDoc commit your copy started from, then merge as usual:diff --git a/src/lib/update-workflow.test.ts b/src/lib/update-workflow.test.tsindex 5e4ee7f..f903b71 100644--- a/src/lib/update-workflow.test.ts+++ b/src/lib/update-workflow.test.ts@@ -466,6 +466,53 @@ test("adding the token later brings in the workflow files that were left", () =>assert.doesNotMatch(after.summary, /SIGNUDOC_UPDATE_TOKEN/);});+test("workflow files left behind do not block the next release", () => {+ const upstream = makeUpstream();+ const { origin } = makeCopy(upstream);++ assert.equal(runUpdate(checkout(origin), upstream).status, 0);+ squashMerge(origin, "signudoc-update/v0.2.0");++ // v0.3.0 changes the same line of ci.yml that this copy never took.+ write(+ upstream,+ ".github/workflows/ci.yml",+ "name: CI\non: [push, pull_request]\n",+ );+ write(upstream, "src/app.ts", "export const a = 1;\nexport const b = 4;\n");+ git(upstream, "commit", "--quiet", "-am", "Third");+ git(upstream, "tag", "v0.3.0");++ const next = runUpdate(checkout(origin), upstream, { version: "v0.3.0" });++ assert.equal(next.status, 0, next.stderr + next.summary);+ assert.equal(+ show(origin, "signudoc-update/v0.3.0", "src/app.ts"),+ "export const a = 1;\nexport const b = 4;",+ );+ assert.equal(+ show(origin, "signudoc-update/v0.3.0", ".github/workflows/ci.yml"),+ "name: CI",+ );++ // And with the token, both releases' workflow changes arrive at once.+ squashMerge(origin, "signudoc-update/v0.3.0");+ const withToken = runUpdate(checkout(origin), upstream, {+ hasToken: true,+ version: "v0.3.0",+ });++ assert.equal(withToken.status, 0, withToken.stderr + withToken.summary);+ assert.equal(+ show(+ origin,+ "signudoc-update/v0.3.0-workflows",+ ".github/workflows/ci.yml",+ ),+ "name: CI\non: [push, pull_request]",+ );+});+test("an unclear starting point stops, and based_on settles it", () => {// Two SignuDoc commits equally far from the copy's edited first commit.const upstream = path.join(scratch, `upstream-${String((counter += 1))}`);