Skip to content

Commit

Permalink
👽 chore: Update workflows outputs to match github's new standard (#5)
Browse files Browse the repository at this point in the history
# Description

Changed the `set-output` command to use `$GITHUB_OUTPUT` in accordance
with [this
article](https://github.blog/changelog/2022-10-11-github-actions-deprecating-save-state-and-set-output-commands/)
Added workflow output using the `$GITHUB_STEP_SUMMARY` file for precommit

## Type of change

:bug: Bug fix (non-breaking change which fixes an issue)
:sparkles: New feature (non-breaking change which adds functionality)

# Checklist:

- [X] My code follows the style guidelines of this project
- [X] I have performed a self-review of my own code
- [X] I have made corresponding changes to the documentation
- [X] My changes generate no new warnings
- [X] I have added tests that prove my fix is effective or that my
feature works
- [X] New and existing unit tests pass locally with my changes
- [X] Any dependent changes have been merged and published in downstream
modules
  • Loading branch information
gsuquet authored Nov 29, 2023
1 parent 594bae9 commit 83f582a
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 28 deletions.
32 changes: 16 additions & 16 deletions .github/workflows/integration-commit-validator.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ jobs:
run: |
if [[ "${{ inputs.format }}" == "custom" ]]; then
if [[ -z "${{ inputs.regex }}" ]]; then
echo "Custom format specified but no regex provided"
echo "Please provide a regex to validate against"
echo "::set-output name=missing_regex::Custom format specified but no regex provided\nPlease provide a regex to validate against"
echo "Custom format specified but no regex provided" >> $GITHUB_STEP_SUMMARY
echo "Please provide a regex to validate against" >> $GITHUB_STEP_SUMMARY
echo "missing_regex=Custom format specified but no regex provided\nPlease provide a regex to validate against" >> $GITHUB_OUTPUT
exit 1
fi
fi
Expand All @@ -54,16 +54,16 @@ jobs:
id: set_regex
run: |
if [[ "${{ inputs.format }}" == "conventional" ]]; then
echo "::set-output name=regex::^[a-z_]+(!)?(: .*)?$"
echo "regex=^[a-z_]+(!)?(: .*)?$" >> $GITHUB_OUTPUT
elif [[ "${{ inputs.format }}" == "gitmoji" ]]; then
echo "::set-output name=regex::^:[a-z_]+: [a-z_]+(!)?(: .*)?$"
echo "regex=^:[a-z_]+: [a-z_]+(!)?(: .*)?$" >> $GITHUB_OUTPUT
elif [[ "${{ inputs.format }}" == "custom" ]]; then
echo "::set-output name=regex::${{ inputs.regex }}"
echo "regex=${{ inputs.regex }}" >> $GITHUB_OUTPUT
else
echo "Invalid format specified"
echo "Valid formats are: conventional, gitmoji and custom"
echo "Custom format requires a regex to be provided"
echo "::set-output name=invalid_format::Invalid format specified\nValid formats are: conventional, gitmoji and custom\nCustom format requires a regex to be provided"
echo "Invalid format specified" >> $GITHUB_STEP_SUMMARY
echo "Valid formats are: conventional, gitmoji and custom" >> $GITHUB_STEP_SUMMARY
echo "Custom format requires a regex to be provided" >> $GITHUB_STEP_SUMMARY
echo "invalid_format=Invalid format specified\nValid formats are: conventional, gitmoji and custom\nCustom format requires a regex to be provided" >> $GITHUB_OUTPUT
exit 1
fi
Expand All @@ -78,12 +78,12 @@ jobs:
id: validate
run: |
if echo "${{ inputs.commit_or_pr_title }}" | grep -Pq "${{ needs.setup.outputs.regex }}"; then
echo "Commit or PR title format is correct"
echo "::set-output name=result::true"
echo "::set-output name=description::Commit or PR title format is correct"
echo "Commit or PR title format is correct" >> $GITHUB_STEP_SUMMARY
echo "result=true" >> $GITHUB_OUTPUT
echo "description=Commit or PR title format is correct" >> $GITHUB_OUTPUT
else
echo "Commit or PR title format is incorrect"
echo "::set-output name=result::false"
echo "::set-output name=description::Commit or PR title format is incorrect"
echo "Commit or PR title format is incorrect" >> $GITHUB_STEP_SUMMARY
echo "result=false" >> $GITHUB_OUTPUT
echo "description=Commit or PR title format is incorrect" >> $GITHUB_OUTPUT
exit 1
fi
35 changes: 24 additions & 11 deletions .github/workflows/integration-linter-pre-commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,8 @@ on:
required: false
type: string

outputs:
result:
description: The result of the pre-commit run
value: ${{ jobs.pre-commit.outputs.result }}

jobs:
pre-commit:
outputs:
result: ${{ steps.pre-commit.outputs.result }}
runs-on: ubuntu-latest
steps:
- name: Checkout repository
Expand All @@ -37,11 +30,31 @@ jobs:
run: pip install pre-commit

- name: Run pre-commit hooks on all files
run: pre-commit run --all-files --show-diff-on-failure | tee results.txt
run: pre-commit run --all-files --show-diff-on-failure | tee output.txt

- name: Set pre-commit result as output
- name: Display results in the GitHub Actions summary
id: pre-commit
run: |
result=$(cat results.txt)
echo "::set-output name=result::$result"
output=$(cat output.txt)
output=$(echo "$output" | grep -v '\[INFO\]')
output=$(echo "$output" | sed 's/Passed/:white_check_mark:/g')
output=$(echo "$output" | sed 's/Skipped/:ballot_box_with_check:/g')
output=$(echo "$output" | sed 's/Failed/:x:/g')
# Exclude empty lines
output=$(echo "$output" | grep -v '^$')
# Exclude lines that start with '-'
output=$(echo "$output" | grep -v '^-')
# Exclude lines that start with 'Fixing'
output=$(echo "$output" | grep -v '^Fixing')
# Use awk to format the output into a markdown table, removing the dots
output=$(echo "$output" | awk -F':' '{gsub(/\.+/, "", $1); print "| " $1 " | :" $2 ":|"}')
echo "| Check | Result |" >> $GITHUB_STEP_SUMMARY
echo "| --- | --- |" >> $GITHUB_STEP_SUMMARY
echo "$output" >> $GITHUB_STEP_SUMMARY
shell: bash
2 changes: 1 addition & 1 deletion .github/workflows/integration-modification-script.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
- name: Detect changes
id: detect_changes
run: |
git diff --quiet || echo "::set-output name=changed::true"
git diff --quiet || echo "changed=true" >> $GITHUB_OUTPUT
- name: Commit changes
if: steps.detect_changes.outputs.changed == 'true'
Expand Down
21 changes: 21 additions & 0 deletions scripts/pre_commit_output_formator.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
output=$(cat ./test/pre_commit_output.txt)
output=$(echo "$output" | grep -v '\[INFO\]')
output=$(echo "$output" | sed 's/Passed/:white_check_mark:/g')
output=$(echo "$output" | sed 's/Skipped/:ballot_box_with_check:/g')
output=$(echo "$output" | sed 's/Failed/:x:/g')

# Exclude empty lines
output=$(echo "$output" | grep -v '^$')

# Exclude lines that start with '-'
output=$(echo "$output" | grep -v '^-')

# Exclude lines that start with 'Fixing'
output=$(echo "$output" | grep -v '^Fixing')

# Use awk to format the output into a markdown table, removing the dots
output=$(echo "$output" | awk -F':' '{gsub(/\.+/, "", $1); print "| " $1 " | :" $2 ":|"}')

echo "| Check | Result |" > ./test/pre_commit_output.md
echo "| --- | --- |" >> ./test/pre_commit_output.md
echo "$output" >> ./test/pre_commit_output.md
16 changes: 16 additions & 0 deletions test/pre_commit_output.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
| Check | Result |
| --- | --- |
| check for merge conflicts | :white_check_mark:|
| don't commit to branch | :white_check_mark:|
| Update markdown table of contents | :white_check_mark:|
| Detect secrets | :white_check_mark:|
| trim trailing whitespace | :white_check_mark:|
| fix end of files | :white_check_mark:|
| check json(no files to check) | :ballot_box_with_check:|
| check yaml | :white_check_mark:|
| validate pre-commit manifest(no files to check) | :ballot_box_with_check:|
| Pretty format YAML | :white_check_mark:|
| check for added large files | :white_check_mark:|
| check for added large files with git lfs | :x:|
| Fixing test/pre_commit_outputtxt | ::|
| check for added large files with git lfs | :white_check_mark:|
19 changes: 19 additions & 0 deletions test/pre_commit_output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
check for merge conflicts................................................Passed
don't commit to branch...................................................Passed
Update markdown table of contents........................................Passed
Detect secrets...........................................................Passed
trim trailing whitespace.................................................Passed
fix end of files.........................................................Passed
check json...........................................(no files to check)Skipped
check yaml...............................................................Passed
validate pre-commit manifest.........................(no files to check)Skipped
Pretty format YAML.......................................................Passed
check for added large files..............................................Passed
check for added large files with git lfs.................................Failed
- hook id: check-added-large-files-with-git-lfs
- exit code: 1
- files were modified by this hook

Fixing test/pre_commit_output.txt

check for added large files with git lfs.................................Passed

0 comments on commit 83f582a

Please sign in to comment.