Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
maruf-pfc authored Oct 30, 2024
1 parent 599ab15 commit d5d5182
Show file tree
Hide file tree
Showing 8 changed files with 688 additions and 0 deletions.
29 changes: 29 additions & 0 deletions PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# What does this PR do?

Add resource(s) | Remove resource(s) | Add info | Improve repo

## Description

Please provide a brief description of your changes and the purpose of this pull request.

## Why is this valuable (or not)?

## How do we know it's really free?

## Changes Made

- [ ] Added new resources
- [ ] Updated existing resources
- [ ] Fixed bugs
- [ ] Other (please specify):

## Checklist

- [ ] I have read the contributing guidelines.
- [ ] My code follows the code style of this project.
- [ ] I have tested my changes and they work as expected.
- [ ] I have updated the documentation if necessary.

## Additional Notes

Any additional information you would like to share.
105 changes: 105 additions & 0 deletions actions/awesomebot-gh-summary-action/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
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.community/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 = $_
if ($file -match "\s+" ) {
continue # is empty string
}
$abr_file = $env:INPUT_AB_ROOT + "/ab-results-" + ($file -replace "[/\\]","-") + "-markdown-table.json"
try {
$json = Get-Content $abr_file | ConvertFrom-Json
} catch {
$message = $_
echo "::error ::$message" # Notify as GitHub Actions annotation
continue # Don't crash!!
}
$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**)"
}
}
# 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
if: ${{ fromJson(inputs.write) }}
shell: bash
env:
INPUT_TEXT: ${{ steps.generate.outputs.text }}
INPUT_WRITE: ${{ inputs.write }}
run: |
echo "$INPUT_TEXT" >> $GITHUB_STEP_SUMMARY
37 changes: 37 additions & 0 deletions dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Github Dependabot config file
# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates

version: 2
updates:

# Maintain dependencies for GitHub Actions
- package-ecosystem: "github-actions"
# Workflow files stored in the
# default location of `.github/workflows`
directory: "/"
schedule:
interval: "weekly"
day: "friday"
time: "12:00"
timezone: "Bangladesh/Dhaka"
# Specify labels for `gha` pull requests
labels:
- "🔗 dependencies"
- "🔗 dependencies:github-actions"
- "🤖 automation"
commit-message:
# Prefix all commit messages with `chore` (follow conventional-commits)
# include a list of updated dependencies
prefix: "chore"
include: "scope"
# Allow up to N open pull requests (0 to disable)
open-pull-requests-limit: 10
pull-request-branch-name:
# Separate sections of the branch name with a hyphen
# for example, `dependabot/github_actions/actions/checkout-2.3.1`
separator: "/"
# Add the arrays of assignees and reviewers
assignees:
- "bangla-programming-resources/maintainers"
reviewers:
- "bangla-programming-resources/reviewers"
116 changes: 116 additions & 0 deletions workflows/check-urls.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
name: Check URLs from changed files

on:
push:
pull_request:

permissions:
# needed for checkout code
contents: read

# This allows a subsequently queued workflow run to interrupt/wait for previous runs
concurrency:
group: '${{ github.workflow }} @ ${{ github.run_id }}'
cancel-in-progress: false # true = interrupt, false = wait

jobs:

# 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
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 "fetch_depth=0" >> $GITHUB_OUTPUT
if [ "${{ github.event_name }}" == "pull_request" ]; then
echo "fetch_depth=0" >> $GITHUB_OUTPUT
fi
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: ${{ steps.set-params.outputs.fetch-depth }}
- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@v45.0.3
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
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
- name: Install awesome_bot
run: |
gem install awesome_bot
- name: Set output
id: set-output
run: echo "FILENAME=$(echo ${{ matrix.file }} | grep -oE '[a-zA-Z0-9_-]+(\.yml|\.md)')" >> "$GITHUB_OUTPUT"
- name: "Check URLs of file: ${{ matrix.file }}"
run: |
awesome_bot "${{ matrix.file }}" --allow-redirect --allow-dupe --allow-ssl || true;
- uses: actions/upload-artifact@v4
with:
name: ${{ steps.set-output.outputs.FILENAME}}
path: ${{ github.workspace }}/ab-results-*.json


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: ${{ steps.set-output.outputs.FILENAME}}
- name: Generate Summary Report
uses: ./.github/actions/awesomebot-gh-summary-action
with:
ab-root: ${{ github.workspace }}
files: ${{ needs.get-changed-files.outputs.files }}
separator: " "
append-heading: ${{ true }}
55 changes: 55 additions & 0 deletions 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: ["bangla-programming-resources-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
Loading

0 comments on commit d5d5182

Please sign in to comment.