patch: update deps #60
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Push test | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
check_commits_test: | |
name: Some testing with checking commit messages on push | |
runs-on: ubuntu-latest | |
steps: | |
- name: Dump context | |
run: | | |
echo "::group::github" | |
echo '${{ toJSON(github) }}' | |
echo "::endgroup::" | |
echo "::group::github.event" | |
echo '${{ toJSON(github.event) }}' | |
echo "::endgroup::" | |
echo "::group::github.event.head_commit" | |
echo '${{ toJSON(github.event.head_commit) }}' | |
echo "::endgroup::" | |
echo "::group::github.event.commits" | |
echo '${{ toJSON(github.event.commits) }}' | |
echo "::endgroup::" | |
- name: Check commits | |
id: check-commits | |
uses: actions/github-script@v7 | |
env: | |
COMMITS_JSON: ${{ toJSON( github.event.commits ) }} | |
TITLE_REGEX: '^Something: ' # Regex without the '/' boundary characters | |
BODY_REGEX: 'test' # Regex without the '/' boundary characters | |
# For special console.log()'s, see also: | |
# https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions | |
with: | |
# result-encoding: string | |
script: | | |
const { COMMITS_JSON, TITLE_REGEX, BODY_REGEX } = process.env; | |
console.log('::group::Regexes'); | |
console.log('Title:', TITLE_REGEX ); | |
console.log('Body:', BODY_REGEX ); | |
console.log('::endgroup::'); | |
console.log('::group::Commits JSON'); | |
console.log( COMMITS_JSON ); | |
console.log('::endgroup::'); | |
const _commits = JSON.parse( COMMITS_JSON ); | |
console.log('::group::Parsed JSON'); | |
console.log( _commits ); | |
console.log('::endgroup::'); | |
const commits = _commits.map( commit => { | |
const msg = commit.message.split(/\r?\n/); | |
return { | |
// author: commit.author.username, | |
title: msg[0], | |
body: (msg.slice(2) || [''] ).join('\n'), | |
}; | |
}); | |
console.log('::group::Commits'); | |
console.log( commits ); | |
console.log('::endgroup::'); | |
// .some() or .every() | |
const any_title_matches = TITLE_REGEX.length ? commits.map( c => c.title ).some( v => v.match( new RegExp( TITLE_REGEX, 'mi' ) ) ) : false; | |
const any_body_matches = BODY_REGEX.length ? commits.map( c => c.body ).some( v => v.match( new RegExp( BODY_REGEX, 'mi' ) ) ) : false; | |
// return any_title_matches || any_body_matches ? 'true': 'false'; | |
return any_title_matches || any_body_matches; | |
- name: Test was true | |
if: fromJSON( steps.check-commits.outputs.result ) | |
run: echo YES | |
- name: Test was false | |
if: ${{ ! fromJSON( steps.check-commits.outputs.result ) }} | |
run: echo NO | |
- name: Write job summary | |
run: | | |
echo "### Hello world! :rocket:" >> $GITHUB_STEP_SUMMARY | |
echo "" >> $GITHUB_STEP_SUMMARY | |
echo "* This" >> $GITHUB_STEP_SUMMARY | |
echo "* all" >> $GITHUB_STEP_SUMMARY | |
echo "* went" >> $GITHUB_STEP_SUMMARY | |
echo "* well! (${{ steps.check-commits.outputs.result }})" >> $GITHUB_STEP_SUMMARY |