Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Simplify dependency update publishing with Git

Manav Rathid5027e2224d8
diff --git a/.github/workflows/dependabot-follow-up.yml b/.github/workflows/dependabot-follow-up.yml
index d6445937d2..565b507e72 100644
--- a/.github/workflows/dependabot-follow-up.yml
+++ b/.github/workflows/dependabot-follow-up.yml
@@ -142,24 +142,24 @@ jobs:
matrix:
pr: ${{ fromJSON(needs.find.outputs.prs) }}
steps:
+ - uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3.2.0
+ id: app
+ with:
+ client-id: ${{ secrets.ENTE_AGENT_GH_CLIENT_ID }}
+ private-key: ${{ secrets.ENTE_AGENT_GH_APP_PRIVATE_KEY }}
+ permission-contents: write
+ permission-pull-requests: write
+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ matrix.pr.head }}
- persist-credentials: false
+ token: ${{ steps.app.outputs.token }}
- uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
name: dependency-${{ matrix.pr.number }}
path: ${{ runner.temp }}/result
- - uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3.2.0
- id: app
- with:
- client-id: ${{ secrets.ENTE_AGENT_GH_CLIENT_ID }}
- private-key: ${{ secrets.ENTE_AGENT_GH_APP_PRIVATE_KEY }}
- permission-contents: write
- permission-pull-requests: write
-
- name: Publish changes and report
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
env:
@@ -170,7 +170,7 @@ jobs:
script: |
const { readFileSync } = require("node:fs");
const { execFileSync } = require("node:child_process");
- const git = (...args) => execFileSync("git", args, { maxBuffer: 50 * 1024 * 1024 });
+ const git = (...args) => execFileSync("git", args, { stdio: "inherit" });
const repo = context.repo;
const head = process.env.PR_HEAD;
const { data: pr } = await github.rest.pulls.get({ ...repo, pull_number: Number(process.env.PR_NUMBER) });
@@ -181,26 +181,11 @@ jobs:
const report = readFileSync(`${result}/report.md`, "utf8").trim();
if (readFileSync(`${result}/changes.patch`).length) {
git("apply", "--index", `${result}/changes.patch`);
- const files = git("diff", "--cached", "--raw", "-z", "--no-renames").toString().split("\0").slice(0, -1);
- const additions = [], deletions = [];
- for (let i = 0; i < files.length; i += 2) {
- const [oldMode, mode, , , status] = files[i].slice(1).split(" ");
- const path = files[i + 1];
- if (status === "D") deletions.push({ path });
- else {
- if (mode !== "100644" && mode !== "100755" ||
- mode !== oldMode && !(oldMode === "000000" && mode === "100644"))
- throw new Error(`Cannot publish file mode change: ${path}`);
- additions.push({ path, contents: git("show", `:${path}`).toString("base64") });
- }
- }
- await github.graphql(`mutation($input: CreateCommitOnBranchInput!) { createCommitOnBranch(input: $input) { commit { oid } } }`, {
- input: {
- branch: { repositoryNameWithOwner: `${repo.owner}/${repo.repo}`, branchName: pr.head.ref },
- expectedHeadOid: head, message: { headline: "Prepare dependency updates" },
- fileChanges: { additions, deletions },
- },
- });
+ const { data: bot } = await github.rest.users.getByUsername({ username: "ente-agent[bot]" });
+ git("config", "user.name", bot.login);
+ git("config", "user.email", `${bot.id}+${bot.login}@users.noreply.github.com`);
+ git("commit", "-m", "Prepare dependency updates");
+ git("push", `--force-with-lease=refs/heads/${pr.head.ref}:${head}`, "origin", `HEAD:refs/heads/${pr.head.ref}`);
}
if (report) await github.rest.issues.createComment({
...repo, issue_number: pr.number,