Skip to content

Commit

Permalink
Merge branch 'main' into maintenance/homogenize-in-process-notes
Browse files Browse the repository at this point in the history
  • Loading branch information
eshellman committed Nov 22, 2023
2 parents c3d5495 + 4ad6bb5 commit 11b884c
Show file tree
Hide file tree
Showing 114 changed files with 4,777 additions and 1,547 deletions.
13 changes: 7 additions & 6 deletions .github/actions/awesomebot-gh-summary-action/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,13 @@ runs:
}
}
# 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"
# set multiline output (the way of prevent script injection is with random delimiters)
# https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#multiline-strings
# https://github.com/orgs/community/discussions/26288#discussioncomment-3876281
$delimiter = (openssl rand -hex 8) | Out-String
echo "text<<$delimiter" >> $env:GITHUB_OUTPUT
echo "$text" >> $env:GITHUB_OUTPUT
echo "$delimiter" >> $env:GITHUB_OUTPUT
- name: Write output
Expand Down
106 changes: 69 additions & 37 deletions .github/workflows/check-urls.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
pull_request:

permissions:
# needed for checkout code
contents: read

# This allows a subsequently queued workflow run to interrupt/wait for previous runs
Expand All @@ -13,69 +14,100 @@ concurrency:
cancel-in-progress: false # true = interrupt, false = wait

jobs:
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 only current commit (by default)
# 2: retrieve until the preceding commit
- name: Determine workflow parameters
id: init-params
get-changed-files:
name: Get changed files
runs-on: ubuntu-latest
outputs:
fetch-depth: ${{ steps.set-params.outputs.fetch-depth }}
files: ${{ steps.set-files.outputs.files }}
files-len: ${{ steps.set-files.outputs.files-len }}
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- name: Determine workflow params
id: set-params
run: |
echo "::set-output name=fetch_depth::0";
echo "fetch_depth=0" >> $GITHUB_OUTPUT
if [ "${{ github.event_name }}" == "pull_request" ]; then
echo "::set-output name=fetch_depth::0";
echo "fetch_depth=0" >> $GITHUB_OUTPUT
fi
- uses: actions/checkout@v3
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: ${{ steps.init-params.outputs.fetch_depth }}

fetch-depth: ${{ steps.set-params.outputs.fetch-depth }}
- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@v30.0.0
uses: tj-actions/changed-files@v40.1.1
with:
separator: " "
json: true
- id: set-files
run: |
echo "${{ steps.changed-files.outputs.all_changed_files }}" \
| jq --raw-output '. | join(" ")' \
| sed -e 's/^/files=/' \
>> $GITHUB_OUTPUT
echo "${{ steps.changed-files.outputs.all_changed_files }}" \
| jq --raw-output '. | length' \
| sed -e 's/^/files-len=/' \
>> $GITHUB_OUTPUT
- id: set-matrix
run: |
echo "{\"file\":${{ steps.changed-files.outputs.all_changed_files }}}" \
| sed -e 's/^/matrix=/' \
>> $GITHUB_OUTPUT
- uses: ruby/setup-ruby@v1
check-urls:
name: Check @ ${{ matrix.file }}
if: ${{ fromJSON(needs.get-changed-files.outputs.files-len) > 0 }}
needs: [get-changed-files]
runs-on: ubuntu-latest
strategy:
matrix: ${{ fromJSON(needs.get-changed-files.outputs.matrix) }}
max-parallel: 10
fail-fast: false
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: ${{ needs.get-changed-files.outputs.fetch-depth }}
- name: Setup Ruby v2.6
uses: ruby/setup-ruby@v1
with:
ruby-version: 2.6

- run: |
- name: Install awesome_bot
run: |
gem install awesome_bot
- name: Check each changed file
- name: "Check URLs of file: ${{ matrix.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;
awesome_bot "${{ matrix.file }}" --allow-redirect --allow-dupe --allow-ssl || true;
- uses: actions/upload-artifact@v3
with:
name: awesomebot-results
path: ${{ github.workspace }}/ab-results-*.json

- name: Generate Summary Report using AwesomeBot results

reporter:
name: GitHub report
needs: [get-changed-files, check-urls]
runs-on: ubuntu-latest
steps:
- name: Checkout # for having the sources of the local action
uses: actions/checkout@v4
# download and unzip the ab-results-*.json generated by job-matrix: check-urls
- uses: actions/download-artifact@v3
with:
name: awesomebot-results
- name: Generate Summary Report
uses: ./.github/actions/awesomebot-gh-summary-action
with:
ab-root: ${{ github.workspace }}
files: ${{ steps.changed-files.outputs.all_changed_files }}
files: ${{ needs.get-changed-files.outputs.files }}
separator: " "
append-heading: ${{ true }}
55 changes: 55 additions & 0 deletions .github/workflows/comment-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: Comment on the pull request

on:
workflow_run:
workflows: ["free-programming-books-lint"]
types:
- completed

jobs:
upload:
permissions:
pull-requests: write
runs-on: ubuntu-latest
if: >
${{ github.event.workflow_run.event == 'pull_request' &&
github.event.workflow_run.conclusion == 'success' }}
steps:
- name: 'Download artifact'
uses: actions/github-script@v7
with:
script: |
let allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: context.payload.workflow_run.id,
});
let matchArtifact = allArtifacts.data.artifacts.filter((artifact) => {
return artifact.name == "pr"
})[0];
let download = await github.rest.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: matchArtifact.id,
archive_format: 'zip',
});
let fs = require('fs');
fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/pr.zip`, Buffer.from(download.data));
- name: 'Unzip artifact'
run: unzip pr.zip

- name: 'Comment on PR'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
if [ -s error.log ]
then
gh pr comment $(<PRurl) -b "Linter failed, fix the error(s):
\`\`\`
$(cat error.log)
\`\`\`"
gh pr edit $(<PRurl) --add-label "linter error"
else
gh pr edit $(<PRurl) --remove-label "linter error"
fi
8 changes: 5 additions & 3 deletions .github/workflows/detect-conflicting-prs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:

- name: Label conflicting PRs that are open
id: pr-labeler
uses: eps1lon/actions-label-merge-conflict@v2.0.1
uses: eps1lon/actions-label-merge-conflict@v2.1.0
with:
repoToken: ${{ secrets.GITHUB_TOKEN }}
retryAfter: 30 # seconds
Expand All @@ -51,10 +51,12 @@ jobs:
run: |
echo "$INPUT_PRS" \
| jq --compact-output --raw-output 'to_entries | map({number: .key, dirty: .value})' \
| sed -e 's/^/::set-output name=prs::/'
| sed -e 's/^/prs=/' \
>> $GITHUB_OUTPUT
echo "$INPUT_PRS" \
| jq --raw-output 'to_entries | length' \
| sed -e 's/^/::set-output name=prs-len::/'
| sed -e 's/^/prs-len=/' \
>> $GITHUB_OUTPUT
env:
INPUT_PRS: ${{ steps.pr-labeler.outputs.prDirtyStatuses }}

Expand Down
27 changes: 20 additions & 7 deletions .github/workflows/fpb-lint.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: free-programming-books-lint

on: [push, pull_request]
on: [pull_request]

permissions:
contents: read
Expand All @@ -11,13 +11,26 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Use Node.js
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: '16.x'
- run: npm install -g free-programming-books-lint
- run: fpb-lint ./books/
- run: fpb-lint ./casts/
- run: fpb-lint ./courses/
- run: fpb-lint ./more/

- name: Pull Request
run: |
fpb-lint books casts courses more &> output.log
- name: Clean output and create artifacts
if: always()
run: |
mkdir -p ./pr
echo ${{ github.event.pull_request.html_url }} > ./pr/PRurl
cat output.log | sed -E 's:/home/runner/work/free-programming-books/|⚠.+::' | uniq > ./pr/error.log
- uses: actions/upload-artifact@v3
if: always()
with:
name: pr
path: pr/
32 changes: 20 additions & 12 deletions .github/workflows/stale.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
pull-requests: write
steps:
- name: Stale issues
uses: actions/stale@v6
uses: actions/stale@v8
id: stale-issues
with:
debug-only: ${{ github.event.inputs.debug-only == 'true' }}
Expand Down Expand Up @@ -81,10 +81,10 @@ jobs:
stale-pr-label: " "

- name: Print outputs for issues
run: echo ${{ join(steps.stale-issues.outputs.*, ',') }}
run: echo ${{ format('{0},{1}', toJSON(steps.stale-issues.outputs.staled-issues-prs), toJSON(steps.stale-issues.outputs.closed-issues-prs)) }}

- name: Stale Pull Requests
uses: actions/stale@v6
uses: actions/stale@v8
id: stale-prs
with:
debug-only: ${{ github.event.inputs.debug-only == 'true' }}
Expand Down Expand Up @@ -120,7 +120,7 @@ jobs:
stale-issue-label: " "

- name: Print outputs for PRs
run: echo ${{ join(steps.stale-prs.outputs.*, ',') }}
run: echo ${{ format('{0},{1}', toJSON(steps.stale-prs.outputs.staled-issues-prs), toJSON(steps.stale-prs.outputs.closed-issues-prs)) }}

## Removing private properties from each JSON object and compute array length
## TODO: Delete these set-* workarounds when resolve actions/stale#806 ?
Expand All @@ -129,17 +129,21 @@ jobs:
run: |
echo $INPUT_ISSUES \
| jq --compact-output --raw-output 'del(.[] | .[to_entries[] | .key | select(startswith("_"))])' \
| sed -e 's/^/::set-output name=issues::/'
| sed -e 's/^/issues=/' \
>> $GITHUB_OUTPUT
echo $INPUT_ISSUES \
| jq --raw-output '. | length' \
| sed -e 's/^/::set-output name=issues-len::/'
| sed -e 's/^/issues-len=/' \
>> $GITHUB_OUTPUT
echo $INPUT_PRS \
| jq --compact-output --raw-output 'del(.[] | .[to_entries[] | .key | select(startswith("_"))])' \
| sed -e 's/^/::set-output name=prs::/'
| sed -e 's/^/prs=/' \
>> $GITHUB_OUTPUT
echo $INPUT_PRS \
| jq --raw-output '. | length' \
| sed -e 's/^/::set-output name=prs-len::/'
| sed -e 's/^/prs-len=/' \
>> $GITHUB_OUTPUT
env:
INPUT_ISSUES: ${{ steps.stale-issues.outputs.staled-issues-prs }}
INPUT_PRS: ${{ steps.stale-prs.outputs.staled-issues-prs }}
Expand All @@ -148,17 +152,21 @@ jobs:
run: |
echo $INPUT_ISSUES \
| jq --compact-output --raw-output 'del(.[] | .[to_entries[] | .key | select(startswith("_"))])' \
| sed -e 's/^/::set-output name=issues::/'
| sed -e 's/^/issues=/' \
>> $GITHUB_OUTPUT
echo $INPUT_ISSUES \
| jq --raw-output '. | length' \
| sed -e 's/^/::set-output name=issues-len::/'
| sed -e 's/^/issues-len=/' \
>> $GITHUB_OUTPUT
echo $INPUT_PRS \
| jq --compact-output --raw-output 'del(.[] | .[to_entries[] | .key | select(startswith("_"))])' \
| sed -e 's/^/::set-output name=prs::/'
| sed -e 's/^/prs=/' \
>> $GITHUB_OUTPUT
echo $INPUT_PRS \
| jq --raw-output '. | length' \
| sed -e 's/^/::set-output name=prs-len::/'
| sed -e 's/^/prs-len=/' \
>> $GITHUB_OUTPUT
env:
INPUT_ISSUES: ${{ steps.stale-issues.outputs.closed-issues-prs }}
INPUT_PRS: ${{ steps.stale-prs.outputs.closed-issues-prs }}
Expand Down
Loading

0 comments on commit 11b884c

Please sign in to comment.