diff --git a/.github/workflows/wgutils-automerge.yml b/.github/workflows/wgutils-automerge.yml new file mode 100644 index 00000000..d82b0d3a --- /dev/null +++ b/.github/workflows/wgutils-automerge.yml @@ -0,0 +1,54 @@ +name: Agenda auto-merge + +on: + pull_request_target: + types: [synchronize, opened, reopened] + +permissions: + contents: write + pull-requests: read + checks: read + +jobs: + validate-and-merge: + if: ${{ github.event.pull_request.base.ref == 'main' }} + runs-on: ubuntu-latest + + steps: + # SECURITY: it's critical we do not check out the source pull request! + - name: Checkout the main branch + uses: actions/checkout@v3 + with: + ref: main + + # We need wgutils to be installed + - run: yarn install + + - name: Wait for checks to pass + env: + GH_TOKEN: ${{ github.token }} + run: | + # Give 15 seconds for any checks to register + sleep 15 + + # Wait for checks to pass + gh pr checks ${{ github.event.pull_request.number }} --fail-fast --watch --required 2>&1 || true + # Now get the result in JSON + CHECKS_OUTPUT="$(gh pr checks ${{ github.event.pull_request.number }} --required --json bucket --jq 'map(.bucket == "pass") | all' 2>&1 || true)" + + if echo "$CHECKS_OUTPUT" | grep -q "no required checks reported"; then + echo "Not required: $CHECKS_OUTPUT" + elif [[ "$CHECKS_OUTPUT" == "true" ]]; then + echo "$CHECKS_OUTPUT" + else + echo "PR state failed? $CHECKS_OUTPUT" + exit 1 + fi + + - name: Automerge if wgutils approves + env: + GH_TOKEN: ${{ github.token }} + run: | + if yarn wgutils can-automerge "${{ github.event.pull_request.number }}" "${{ github.event.pull_request.head.sha }}"; then + gh pr merge "${{ github.event.pull_request.number }}" --squash --auto --match-head-commit "${{ github.event.pull_request.head.sha }}" + fi diff --git a/package-lock.json b/package-lock.json index bfc883b4..cb1c7620 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,7 +11,7 @@ "nodemon": "^2.0.20", "prettier": "^2.3.0", "spec-md": "^3.1.0", - "wgutils": "^0.1.6" + "wgutils": "^1.2.2" } }, "node_modules/@babel/code-frame": { @@ -1698,6 +1698,13 @@ "node": ">=8" } }, + "node_modules/parse-diff": { + "version": "0.11.1", + "resolved": "https://registry.npmjs.org/parse-diff/-/parse-diff-0.11.1.tgz", + "integrity": "sha512-Oq4j8LAOPOcssanQkIjxosjATBIEJhCxMCxPhMu+Ci4wdNmAEdx0O+a7gzbR2PyKXgKPvRLIN5g224+dJAsKHA==", + "dev": true, + "license": "MIT" + }, "node_modules/parse-json": { "version": "5.2.0", "resolved": "https://registry.npmjs.org/parse-json/-/parse-json-5.2.0.tgz", @@ -2081,13 +2088,15 @@ "dev": true }, "node_modules/wgutils": { - "version": "0.1.6", - "resolved": "https://registry.npmjs.org/wgutils/-/wgutils-0.1.6.tgz", - "integrity": "sha512-YJCokALmddvpHvhbbGpL1j/bw+MqjU94FE1GEJxG9Jstt3uAsJtme+B0m/DPfwvRrOmwYOXuYQ+16FY8z7SJHg==", + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/wgutils/-/wgutils-1.2.2.tgz", + "integrity": "sha512-fN4OwgcO5Lx2yyXbWSSC4SD9O0SisFsKBBgZ1ICc5DtesJC07BshWHpak6xgcftS9z5tsJdDB5bRG/LgE7CqiA==", "dev": true, + "license": "MIT", "dependencies": { "date-fns": "^2", "date-fns-tz": "^2.0.0", + "parse-diff": "0.11.1", "yargs": "^17.7.2", "zod": "^3.22.4" }, @@ -3552,6 +3561,12 @@ "callsites": "^3.1.0" } }, + "parse-diff": { + "version": "0.11.1", + "resolved": "https://registry.npmjs.org/parse-diff/-/parse-diff-0.11.1.tgz", + "integrity": "sha512-Oq4j8LAOPOcssanQkIjxosjATBIEJhCxMCxPhMu+Ci4wdNmAEdx0O+a7gzbR2PyKXgKPvRLIN5g224+dJAsKHA==", + "dev": true + }, "parse-json": { "version": "5.2.0", "resolved": "https://registry.npmjs.org/parse-json/-/parse-json-5.2.0.tgz", @@ -3815,13 +3830,14 @@ "dev": true }, "wgutils": { - "version": "0.1.6", - "resolved": "https://registry.npmjs.org/wgutils/-/wgutils-0.1.6.tgz", - "integrity": "sha512-YJCokALmddvpHvhbbGpL1j/bw+MqjU94FE1GEJxG9Jstt3uAsJtme+B0m/DPfwvRrOmwYOXuYQ+16FY8z7SJHg==", + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/wgutils/-/wgutils-1.2.2.tgz", + "integrity": "sha512-fN4OwgcO5Lx2yyXbWSSC4SD9O0SisFsKBBgZ1ICc5DtesJC07BshWHpak6xgcftS9z5tsJdDB5bRG/LgE7CqiA==", "dev": true, "requires": { "date-fns": "^2", "date-fns-tz": "^2.0.0", + "parse-diff": "0.11.1", "yargs": "^17.7.2", "zod": "^3.22.4" } diff --git a/package.json b/package.json index b92f89c9..f98305fa 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ "nodemon": "^2.0.20", "prettier": "^2.3.0", "spec-md": "^3.1.0", - "wgutils": "^0.1.6" + "wgutils": "^1.2.2" }, "prettier": { "proseWrap": "always",