forked from EbookFoundation/free-programming-books
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge EbookFoundation#7034 into maintenance/homogenize-in-process-notes
- Loading branch information
Showing
40 changed files
with
548 additions
and
374 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
name: 'AwesomeBot Markdown Summary Report' | ||
description: 'Composes the summary report using JSON results of any AwesomeBot execution' | ||
|
||
inputs: | ||
ab-root: | ||
description: 'Path where AwesomeBot result files are written.' | ||
required: true | ||
files: | ||
description: 'A delimited string containing the filenames to process.' | ||
required: true | ||
separator: | ||
description: 'Token used to delimit each filename. Default: " ".' | ||
required: false | ||
default: ' ' | ||
append-heading: | ||
description: 'When should append report heading.' | ||
required: false | ||
default: "false" | ||
write: | ||
description: 'When should append the report to GITHUB_STEP_SUMMARY file descriptor.' | ||
required: false | ||
default: "true" | ||
|
||
outputs: | ||
text: | ||
description: Generated Markdown text. | ||
value: ${{ steps.generate.outputs.text }} | ||
|
||
runs: | ||
using: "composite" | ||
|
||
steps: | ||
|
||
- name: Generate markdown | ||
id: generate | ||
# Using PowerShell | ||
shell: pwsh | ||
# sec: sanatize inputs using environment variables | ||
env: | ||
GITHUB_ACTION_PATH: ${{ github.action_path }} | ||
GITHUB_WORKSPACE: ${{ github.workspace }} | ||
# INPUT_<VARIABLE_NAME> is not available in Composite run steps | ||
# https://github.521000.bestmunity/t/input-variable-name-is-not-available-in-composite-run-steps/127611 | ||
INPUT_AB_ROOT: ${{ inputs.ab-root }} | ||
INPUT_FILES: ${{ inputs.files }} | ||
INPUT_SEPARATOR: ${{ inputs.separator }} | ||
INPUT_APPEND_HEADING: ${{ inputs.append-heading }} | ||
run: | | ||
$text = "" | ||
# Handle optional heading | ||
if ("true" -eq $env:INPUT_APPEND_HEADING) { | ||
$text += "### Report of Checked URLs!" | ||
$text += "`n`n" | ||
$text += "<div align=`"right`" markdown=`"1`">`n`n" | ||
$text += "_Link issues :rocket: powered by [``awesome_bot``](https://github.com/dkhamsing/awesome_bot)_." | ||
$text += "`n`n</div>" | ||
} | ||
# Loop ForEach files | ||
$env:INPUT_FILES -split $env:INPUT_SEPARATOR | ForEach { | ||
$file = $_ | ||
$abr_file = $env:INPUT_AB_ROOT + "/ab-results-" + ($file -replace "[/\\]","-") + "-markdown-table.json" | ||
$json = Get-Content $abr_file | ConvertFrom-Json | ||
$text += "`n`n" | ||
if ("true" -eq $json.error) { | ||
# Highlighting issues counter | ||
$SearchExp = '(?<Num>\d+)' | ||
$ReplaceExp = '**${Num}**' | ||
$text += "`:page_facing_up: File: ``" + $file + "`` (:warning: " + ($json.title -replace $SearchExp,$ReplaceExp) + ")" | ||
# removing where ab attribution lives (moved to report heading) | ||
$text += $json.message -replace "####.*?\n","`n" | ||
} else { | ||
$text += ":page_facing_up: File: ``" + $file + "`` (:ok: **No issues**)" | ||
} | ||
} | ||
# HACK to single line strings (https://trstringer.com/github-actions-multiline-strings/) | ||
$text = $text -replace "`%","%25" | ||
$text = $text -replace "`n","%0A" | ||
$text = $text -replace "`r","%25" | ||
# set output | ||
echo "::set-output name=text::$text" | ||
- name: Write output | ||
if: ${{ fromJson(inputs.write) }} | ||
shell: bash | ||
env: | ||
INPUT_TEXT: ${{ steps.generate.outputs.text }} | ||
INPUT_WRITE: ${{ inputs.write }} | ||
run: | | ||
echo "$INPUT_TEXT" >> $GITHUB_STEP_SUMMARY |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,81 @@ | ||
name: Check URLs from changed files | ||
on: [push, pull_request] | ||
|
||
on: | ||
push: | ||
pull_request: | ||
|
||
permissions: | ||
contents: read | ||
|
||
# This allows a subsequently queued workflow run to interrupt previous runs | ||
concurrency: | ||
group: '${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref || github.run_id }}' | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
job: | ||
check-urls: | ||
runs-on: ubuntu-latest | ||
|
||
outputs: | ||
changed-files: ${{ steps.changed-files.outputs.all_changed_files }} | ||
|
||
steps: | ||
|
||
# NOTE: tj-actions/changed-files. | ||
# For push events you need to include fetch-depth: 0 | 2 depending on your use case. | ||
# 0: retrieve all history for all branches and tags | ||
# 1: retrieve current commit (by default) | ||
# 2: retrieve the preceding commit | ||
- name: Determine workflow parameters | ||
id: init-params | ||
run: | | ||
echo "::set-output name=fetch_depth::0"; | ||
if [ "${{ github.event_name }}" == "pull_request" ]; then | ||
echo "::set-output name=fetch_depth::1"; | ||
fi | ||
- uses: actions/checkout@v3 | ||
- uses: trilom/[email protected] | ||
id: file_changes | ||
with: | ||
output: '' | ||
fetch-depth: ${{ steps.init-params.outputs.fetch_depth }} | ||
|
||
- name: Get changed files | ||
id: changed-files | ||
uses: tj-actions/[email protected] | ||
with: | ||
separator: " " | ||
|
||
- uses: ruby/setup-ruby@v1 | ||
with: | ||
ruby-version: 2.6 | ||
- run: gem install awesome_bot | ||
- run: for i in ${{ steps.file_changes.outputs.files_modified }}; do echo; echo "processing $i"; awesome_bot $i --allow-redirect --allow-dupe --allow-ssl || true; done | ||
|
||
- run: | | ||
gem install awesome_bot | ||
- name: Check each changed file | ||
run: | | ||
# Set field separator | ||
IFS=$' '; | ||
# Processing loop | ||
for file in ${{ steps.changed-files.outputs.all_changed_files }}; do | ||
echo; | ||
echo "::group::Processing file... $file"; | ||
awesome_bot "$file" --allow-redirect --allow-dupe --allow-ssl || true; | ||
echo "::endgroup::"; | ||
done | ||
# Unset field separator | ||
unset IFS; | ||
- uses: actions/upload-artifact@v3 | ||
with: | ||
path: ${{ github.workspace }}/*.json | ||
name: awesomebot-results | ||
path: ${{ github.workspace }}/ab-results-*.json | ||
|
||
- name: Generate Summary Report using AwesomeBot results | ||
uses: ./.github/actions/awesomebot-gh-summary-action | ||
with: | ||
ab-root: ${{ github.workspace }} | ||
files: ${{ steps.changed-files.outputs.all_changed_files }} | ||
separator: " " | ||
append-heading: ${{ true }} |
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
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
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
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
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
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
Oops, something went wrong.