Skip to content

Commit d5d5182

Browse files
authored
Add files via upload
1 parent 599ab15 commit d5d5182

File tree

8 files changed

+688
-0
lines changed

8 files changed

+688
-0
lines changed

PULL_REQUEST_TEMPLATE.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# What does this PR do?
2+
3+
Add resource(s) | Remove resource(s) | Add info | Improve repo
4+
5+
## Description
6+
7+
Please provide a brief description of your changes and the purpose of this pull request.
8+
9+
## Why is this valuable (or not)?
10+
11+
## How do we know it's really free?
12+
13+
## Changes Made
14+
15+
- [ ] Added new resources
16+
- [ ] Updated existing resources
17+
- [ ] Fixed bugs
18+
- [ ] Other (please specify):
19+
20+
## Checklist
21+
22+
- [ ] I have read the contributing guidelines.
23+
- [ ] My code follows the code style of this project.
24+
- [ ] I have tested my changes and they work as expected.
25+
- [ ] I have updated the documentation if necessary.
26+
27+
## Additional Notes
28+
29+
Any additional information you would like to share.
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
name: 'AwesomeBot Markdown Summary Report'
2+
description: 'Composes the summary report using JSON results of any AwesomeBot execution'
3+
4+
inputs:
5+
ab-root:
6+
description: 'Path where AwesomeBot result files are written.'
7+
required: true
8+
files:
9+
description: 'A delimited string containing the filenames to process.'
10+
required: true
11+
separator:
12+
description: 'Token used to delimit each filename. Default: " ".'
13+
required: false
14+
default: ' '
15+
append-heading:
16+
description: 'When should append report heading.'
17+
required: false
18+
default: "false"
19+
write:
20+
description: 'When should append the report to GITHUB_STEP_SUMMARY file descriptor.'
21+
required: false
22+
default: "true"
23+
24+
outputs:
25+
text:
26+
description: Generated Markdown text.
27+
value: ${{ steps.generate.outputs.text }}
28+
29+
runs:
30+
using: "composite"
31+
32+
steps:
33+
34+
- name: Generate markdown
35+
id: generate
36+
# Using PowerShell
37+
shell: pwsh
38+
# sec: sanatize inputs using environment variables
39+
env:
40+
GITHUB_ACTION_PATH: ${{ github.action_path }}
41+
GITHUB_WORKSPACE: ${{ github.workspace }}
42+
# INPUT_<VARIABLE_NAME> is not available in Composite run steps
43+
# https://github.community/t/input-variable-name-is-not-available-in-composite-run-steps/127611
44+
INPUT_AB_ROOT: ${{ inputs.ab-root }}
45+
INPUT_FILES: ${{ inputs.files }}
46+
INPUT_SEPARATOR: ${{ inputs.separator }}
47+
INPUT_APPEND_HEADING: ${{ inputs.append-heading }}
48+
run: |
49+
$text = ""
50+
51+
# Handle optional heading
52+
if ("true" -eq $env:INPUT_APPEND_HEADING) {
53+
$text += "### Report of Checked URLs!"
54+
$text += "`n`n"
55+
$text += "<div align=`"right`" markdown=`"1`">`n`n"
56+
$text += "_Link issues :rocket: powered by [``awesome_bot``](https://github.com/dkhamsing/awesome_bot)_."
57+
$text += "`n`n</div>"
58+
}
59+
60+
# Loop ForEach files
61+
$env:INPUT_FILES -split $env:INPUT_SEPARATOR | ForEach {
62+
$file = $_
63+
if ($file -match "\s+" ) {
64+
continue # is empty string
65+
}
66+
$abr_file = $env:INPUT_AB_ROOT + "/ab-results-" + ($file -replace "[/\\]","-") + "-markdown-table.json"
67+
68+
try {
69+
$json = Get-Content $abr_file | ConvertFrom-Json
70+
} catch {
71+
$message = $_
72+
echo "::error ::$message" # Notify as GitHub Actions annotation
73+
continue # Don't crash!!
74+
}
75+
76+
$text += "`n`n"
77+
if ("true" -eq $json.error) {
78+
# Highlighting issues counter
79+
$SearchExp = '(?<Num>\d+)'
80+
$ReplaceExp = '**${Num}**'
81+
$text += "`:page_facing_up: File: ``" + $file + "`` (:warning: " + ($json.title -replace $SearchExp,$ReplaceExp) + ")"
82+
# removing where ab attribution lives (moved to report heading)
83+
$text += $json.message -replace "####.*?\n","`n"
84+
} else {
85+
$text += ":page_facing_up: File: ``" + $file + "`` (:ok: **No issues**)"
86+
}
87+
}
88+
89+
# set multiline output (the way of prevent script injection is with random delimiters)
90+
# https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#multiline-strings
91+
# https://github.com/orgs/community/discussions/26288#discussioncomment-3876281
92+
$delimiter = (openssl rand -hex 8) | Out-String
93+
echo "text<<$delimiter" >> $env:GITHUB_OUTPUT
94+
echo "$text" >> $env:GITHUB_OUTPUT
95+
echo "$delimiter" >> $env:GITHUB_OUTPUT
96+
97+
98+
- name: Write output
99+
if: ${{ fromJson(inputs.write) }}
100+
shell: bash
101+
env:
102+
INPUT_TEXT: ${{ steps.generate.outputs.text }}
103+
INPUT_WRITE: ${{ inputs.write }}
104+
run: |
105+
echo "$INPUT_TEXT" >> $GITHUB_STEP_SUMMARY

dependabot.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Github Dependabot config file
2+
# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
3+
4+
version: 2
5+
updates:
6+
7+
# Maintain dependencies for GitHub Actions
8+
- package-ecosystem: "github-actions"
9+
# Workflow files stored in the
10+
# default location of `.github/workflows`
11+
directory: "/"
12+
schedule:
13+
interval: "weekly"
14+
day: "friday"
15+
time: "12:00"
16+
timezone: "Bangladesh/Dhaka"
17+
# Specify labels for `gha` pull requests
18+
labels:
19+
- "🔗 dependencies"
20+
- "🔗 dependencies:github-actions"
21+
- "🤖 automation"
22+
commit-message:
23+
# Prefix all commit messages with `chore` (follow conventional-commits)
24+
# include a list of updated dependencies
25+
prefix: "chore"
26+
include: "scope"
27+
# Allow up to N open pull requests (0 to disable)
28+
open-pull-requests-limit: 10
29+
pull-request-branch-name:
30+
# Separate sections of the branch name with a hyphen
31+
# for example, `dependabot/github_actions/actions/checkout-2.3.1`
32+
separator: "/"
33+
# Add the arrays of assignees and reviewers
34+
assignees:
35+
- "bangla-programming-resources/maintainers"
36+
reviewers:
37+
- "bangla-programming-resources/reviewers"

workflows/check-urls.yml

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
name: Check URLs from changed files
2+
3+
on:
4+
push:
5+
pull_request:
6+
7+
permissions:
8+
# needed for checkout code
9+
contents: read
10+
11+
# This allows a subsequently queued workflow run to interrupt/wait for previous runs
12+
concurrency:
13+
group: '${{ github.workflow }} @ ${{ github.run_id }}'
14+
cancel-in-progress: false # true = interrupt, false = wait
15+
16+
jobs:
17+
18+
# NOTE: tj-actions/changed-files.
19+
# For push events you need to include fetch-depth: 0 | 2 depending on your use case.
20+
# 0: retrieve all history for all branches and tags
21+
# 1: retrieve only current commit (by default)
22+
# 2: retrieve until the preceding commit
23+
get-changed-files:
24+
name: Get changed files
25+
runs-on: ubuntu-latest
26+
outputs:
27+
fetch-depth: ${{ steps.set-params.outputs.fetch-depth }}
28+
files: ${{ steps.set-files.outputs.files }}
29+
files-len: ${{ steps.set-files.outputs.files-len }}
30+
matrix: ${{ steps.set-matrix.outputs.matrix }}
31+
steps:
32+
- name: Determine workflow params
33+
id: set-params
34+
run: |
35+
echo "fetch_depth=0" >> $GITHUB_OUTPUT
36+
if [ "${{ github.event_name }}" == "pull_request" ]; then
37+
echo "fetch_depth=0" >> $GITHUB_OUTPUT
38+
fi
39+
- name: Checkout
40+
uses: actions/checkout@v4
41+
with:
42+
fetch-depth: ${{ steps.set-params.outputs.fetch-depth }}
43+
- name: Get changed files
44+
id: changed-files
45+
uses: tj-actions/[email protected]
46+
with:
47+
separator: " "
48+
json: true
49+
- id: set-files
50+
run: |
51+
echo "${{ steps.changed-files.outputs.all_changed_files }}" \
52+
| jq --raw-output '. | join(" ")' \
53+
| sed -e 's/^/files=/' \
54+
>> $GITHUB_OUTPUT
55+
echo "${{ steps.changed-files.outputs.all_changed_files }}" \
56+
| jq --raw-output '. | length' \
57+
| sed -e 's/^/files-len=/' \
58+
>> $GITHUB_OUTPUT
59+
- id: set-matrix
60+
run: |
61+
echo "{\"file\":${{ steps.changed-files.outputs.all_changed_files }}}" \
62+
| sed -e 's/^/matrix=/' \
63+
>> $GITHUB_OUTPUT
64+
65+
66+
check-urls:
67+
name: Check @ ${{ matrix.file }}
68+
if: ${{ fromJSON(needs.get-changed-files.outputs.files-len) > 0 }}
69+
needs: [get-changed-files]
70+
runs-on: ubuntu-latest
71+
strategy:
72+
matrix: ${{ fromJSON(needs.get-changed-files.outputs.matrix) }}
73+
max-parallel: 10
74+
fail-fast: false
75+
steps:
76+
- name: Checkout
77+
uses: actions/checkout@v4
78+
with:
79+
fetch-depth: ${{ needs.get-changed-files.outputs.fetch-depth }}
80+
- name: Setup Ruby v2.6
81+
uses: ruby/setup-ruby@v1
82+
with:
83+
ruby-version: 2.6
84+
- name: Install awesome_bot
85+
run: |
86+
gem install awesome_bot
87+
- name: Set output
88+
id: set-output
89+
run: echo "FILENAME=$(echo ${{ matrix.file }} | grep -oE '[a-zA-Z0-9_-]+(\.yml|\.md)')" >> "$GITHUB_OUTPUT"
90+
- name: "Check URLs of file: ${{ matrix.file }}"
91+
run: |
92+
awesome_bot "${{ matrix.file }}" --allow-redirect --allow-dupe --allow-ssl || true;
93+
- uses: actions/upload-artifact@v4
94+
with:
95+
name: ${{ steps.set-output.outputs.FILENAME}}
96+
path: ${{ github.workspace }}/ab-results-*.json
97+
98+
99+
reporter:
100+
name: GitHub report
101+
needs: [get-changed-files, check-urls]
102+
runs-on: ubuntu-latest
103+
steps:
104+
- name: Checkout # for having the sources of the local action
105+
uses: actions/checkout@v4
106+
# download and unzip the ab-results-*.json generated by job-matrix: check-urls
107+
- uses: actions/download-artifact@v3
108+
with:
109+
name: ${{ steps.set-output.outputs.FILENAME}}
110+
- name: Generate Summary Report
111+
uses: ./.github/actions/awesomebot-gh-summary-action
112+
with:
113+
ab-root: ${{ github.workspace }}
114+
files: ${{ needs.get-changed-files.outputs.files }}
115+
separator: " "
116+
append-heading: ${{ true }}

workflows/comment-pr.yml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: Comment on the pull request
2+
3+
on:
4+
workflow_run:
5+
workflows: ["bangla-programming-resources-lint"]
6+
types:
7+
- completed
8+
9+
jobs:
10+
upload:
11+
permissions:
12+
pull-requests: write
13+
runs-on: ubuntu-latest
14+
if: >
15+
${{ github.event.workflow_run.event == 'pull_request' &&
16+
github.event.workflow_run.conclusion == 'success' }}
17+
steps:
18+
- name: 'Download artifact'
19+
uses: actions/github-script@v7
20+
with:
21+
script: |
22+
let allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({
23+
owner: context.repo.owner,
24+
repo: context.repo.repo,
25+
run_id: context.payload.workflow_run.id,
26+
});
27+
let matchArtifact = allArtifacts.data.artifacts.filter((artifact) => {
28+
return artifact.name == "pr"
29+
})[0];
30+
let download = await github.rest.actions.downloadArtifact({
31+
owner: context.repo.owner,
32+
repo: context.repo.repo,
33+
artifact_id: matchArtifact.id,
34+
archive_format: 'zip',
35+
});
36+
let fs = require('fs');
37+
fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/pr.zip`, Buffer.from(download.data));
38+
39+
- name: 'Unzip artifact'
40+
run: unzip pr.zip
41+
42+
- name: 'Comment on PR'
43+
env:
44+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
45+
run: |
46+
if [ -s error.log ]
47+
then
48+
gh pr comment $(<PRurl) -b "Linter failed, fix the error(s):
49+
\`\`\`
50+
$(cat error.log)
51+
\`\`\`"
52+
gh pr edit $(<PRurl) --add-label "linter error"
53+
else
54+
gh pr edit $(<PRurl) --remove-label "linter error"
55+
fi

0 commit comments

Comments
 (0)