github-action-benchmark icon indicating copy to clipboard operation
github-action-benchmark copied to clipboard

Bug: Commit message does not comply with organisation policy.

Open RowlandBanks opened this issue 5 months ago • 2 comments

Scenario

We have a pre-commit hook that enforces commit messages are in a particular format. For example, it might enforce Semantic Commits, or Conventional Commits.

These hooks may be enforced organisation-wide.

Steps to reproduce

  • Add a hook to enforce a particular style of commit message.
  • Run a benchmarking workflow.

Expected result

  • The commit pushed to Github Pages has a commit message that matches the required style
  • The commit is successfully pushed.

Actual result

  • The following error is received:
remote: commit-msg: failed with exit status 1        
remote: [POLICY] Aborting commit 9e0367e61d255bf5584361d5ce52e2eec170c83a. Your commit message is missing a JIRA ID. e.g. Should start with something like 'ABC-1234: ' -- If your change is too insignificant to require a Jira number, you may add the prefix 'Minor'        
To https://contoso.org/contose/people_service.git
 ! [remote rejected] gh-pages -> gh-pages (pre-receive hook declined)
error: failed to push some refs to 'https://contoso.org/contose/people_service.git'
Warning: Auto-push failed because the remote gh-pages was updated after git pull

Technical implementation

The commit message is created here.

Ideally, the user would be able to specify a message format for the commit message, for example:

      - name: Store benchmark result
        uses: actions/[email protected]
        with:
          name: Benchmark.Net Benchmark
          tool: 'benchmarkdotnet'
          output-file-path: src/Benchmarks/results/Benchmarks-report-full-compressed.json
          auto-push: false
          commit-message-format: "MINOR: add {name} ({tool}) benchmark result for {bench_commit_id}"

A common implementation would be:

const commitTemplate = args.outputFilePath;

function fillTemplate(template, values) {
  return template.replace(/{(.*?)}/g, (match, key) => values[key.trim()] || match);
}

const templateValues = {
  name: name,
  tool: tool,
  bench_commit_id: bench.commit.id}
};

const commitMessage = fillTemplate(commitTemplate, templateValues );

RowlandBanks avatar Mar 22 '24 15:03 RowlandBanks