Skip to content

Commit

Permalink
chore: Update standpoints action with git helpers and check for diffe…
Browse files Browse the repository at this point in the history
…rences before committing
  • Loading branch information
Ackuq committed Jun 2, 2024
1 parent 2db6698 commit a68c8c3
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/update-standpoints.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,5 @@ jobs:

- name: Run action to potentially create PR
uses: ./actions/update-standpoints
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
4 changes: 4 additions & 0 deletions actions/update-standpoints/action.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
name: Update Standpoints
description: Script that updates the party standpoints
inputs:
github-token:
description: GitHub token
required: true
runs:
using: node20
main: dist/index.mjs
2 changes: 1 addition & 1 deletion actions/update-standpoints/src/git-helper.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export async function push() {
await exec(command);
}

export async function hasDiff() {
export async function checkHasDiff() {
const command = ["diff", "--quiet"];
const output = await exec(command);
// Exit code 1 means there are differences
Expand Down
26 changes: 26 additions & 0 deletions actions/update-standpoints/src/github-helper.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import core from "@actions/core";
import github from "@actions/github";

const { context } = github;

const token = core.getInput("github-token");
const client = github.getOctokit(token);

/**
*
* @param {string} title
* @param {string} body
* @param {string} head
* @param {string} base
*/
export async function createPullRequest(title, body, head, base = "main") {
const { data } = await client.rest.pulls.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: title,
body,
head,
base,
});
return data;
}
19 changes: 18 additions & 1 deletion actions/update-standpoints/src/main.mjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
// @ts-check
import github from "@actions/github";

console.log("Hello from update-standpoints!");
import { add, checkHasDiff, checkout, commit, push } from "./git-helper.mjs";

const hasDiff = await checkHasDiff();

if (!hasDiff) {
console.log("No changes detected, exiting...");
process.exit(0);
}

const runId = github.context.runId;
const branchName = `update-standpoints-${runId}`;

// Checkout and push changes
await checkout(branchName, "main");
await add();
await commit("Update standpoints");
await push();

0 comments on commit a68c8c3

Please sign in to comment.