Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add link checking and branch/pr naming and change-log enforcing global workflows for org #21

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions .github/workflows/check-links.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: Check-Links

on:
workflow_call:
secrets:
token:
required: true

concurrency:
group: link-checker-${{ github.repository }}-${{ github.head_ref }}-1
cancel-in-progress: true

env:
FAIL_ON_ERROR: ${{ github.event.schedule == '00 20 1-7 * SUN' || false }}

jobs:
linkChecker:
runs-on: ubuntu-latest
steps:
- name: show
id: show-env
if: ${{ always() }}
run: |
echo "FAIL_ON_ERROR: ${{ env.FAIL_ON_ERROR }}"
echo "BRANCH: ${{ github.ref_name }}"
echo "SCHEDULE: ${{ github.event.schedule }}"
echo "SHA: ${{ github.sha }}"

- name: Restore lychee cache
id: restore-lychee-cache
uses: actions/cache@v3
with:
path: .lycheecache
key: cache-lychee-${{ github.sha }}
restore-keys: cache-lychee-

- name: checkout
id: checkout
if: steps.restore-lychee-cache.outputs.cache-hit != 'true'
uses: actions/checkout@v3
env:
GITHUB_TOKEN: ${{ secrets.token }}

- name: Link Checker Fail on Error - ${{ env.FAIL_ON_ERROR }}
id: lychee
uses: lycheeverse/lychee-action@v1.8.0
with:
fail: ${{ env.FAIL_ON_ERROR }}
env:
GITHUB_TOKEN: ${{ secrets.token }}

- name: Create Issue From File
id: create-issue
if: env.lychee_exit_code != 0 && github.ref_name == 'main'
uses: peter-evans/create-issue-from-file@v4
with:
title: Link Checker Report
content-filepath: ./lychee/out.md
labels: report, automated issue
139 changes: 139 additions & 0 deletions .github/workflows/pre-validate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
name: Prevalidate

on:
workflow_call:
secrets:
token:
required: true
inputs:
validate_changelog:
type: boolean
description: Whether to validate changelogs
required: false
default: false
triage:
type: boolean
description: Whether to perform automated triaging
required: false
default: false

concurrency:
group: pre-validate-${{ github.repository }}-${{ github.event.pull_request.head.ref }}-1
cancel-in-progress: true

jobs:
checks:
runs-on: "ubuntu-latest"
# Ignore dependabot branches
if: ! startsWith(github.event.pull_request.head.ref, 'dependabot/')

steps:
- name: Check out the repository
id: checkout
uses: actions/checkout@v3
env:
GITHUB_TOKEN: ${{ secrets.token }}
with:
fetch-depth: 0
persist-credentials: true

- name: validate Branch Name
id: validate-branch-name
uses: deepakputhraya/action-branch-name@e0f8db53a8e289f1ae6f6c3e8dc70a3d366fd876
with:
regex: '([a-z-0-9]{3,})\/([a-z0-9._-])+' # Regex the branch should match.
# This regex enforces grouping with a Jira ticket number and a lowercase subject
# so something like feat/pi-123/my-branch-for-my-cause would be a valid example
allowed_prefixes: "feat,fix,docs,style,refactor,perf,test,build,ci,chore,revert,deps,dependabot" # All branches should start with the given prefix
ignore: main # Ignore exactly matching branch names from convention
min_length: 4 # Min length of the branch name
max_length: 63 # Max length of the branch name

- name: Verify Changelog Content
id: verify-changed-files
if: ${{ github.event.pull_request.base.ref == 'main' }} && ${{ inputs.validate_changelog == true }}
uses: tj-actions/changed-files@v37
with:
since_last_remote_commit: false
files: |
Changelog.md

- name: Verify Changelog was updated
id: verify-changelog-updated
if: ${{ github.event.pull_request.base.ref == 'main' }} && ${{ inputs.validate_changelog == true }}
run: |
if [ "${{ steps.verify-changed-files.outputs.any_changed }}" == "true" ]; then
echo "The Changelog.md file was updated"
else
echo "The Changelog.md file was not updated"
exit 1
fi

- name: Validate PR title
if: startsWith(github.event.pull_request.head.ref, 'dependabot/')
id: validate-title
uses: amannn/action-semantic-pull-request@c3cd5d1ea3580753008872425915e343e351ab54
env:
GITHUB_TOKEN: ${{ secrets.token }}
with:
# Configure which types are allowed (newline delimited).
# Default: https://github.com/commitizen/conventional-commit-types
types: |
feat
fix
docs
style
refactor
perf
test
build
ci
chore
revert
deps
dependabot
# If the PR only contains a single commit, the action will validate that
# it matches the configured pattern.
validateSingleCommit: true
# For work-in-progress PRs you can typically use draft pull requests
# from GitHub. However, private repositories on the free plan don't have
# this option and therefore this action allows you to opt in to using the
# special "[WIP]" prefix to indicate this state. This will avoid the
# validation of the PR title and the pull request checks remain pending.
# Note that a second check will be reported if this is enabled.
wip: true
# Configure additional validation for the subject based on a regex.
# This example ensures the subject doesn't start with an uppercase character.
# something like feat: PI-150
subjectPattern: ^([a-z-A-Z]{2,3}[-0-9]{1,}[\s\|]*[\s]?)(.+)$
# If `subjectPattern` is configured, you can use this property to override
# the default error message that is shown when the pattern doesn't match.
# The variables `subject` and `title` can be used within the message.
subjectPatternError: |
The subject "{subject}" found in the pull request title "{title}"
didn't match the configured pattern.
The regex pattern is "^([a-z-A-Z]{2,3}[-0-9]{1,}[\s\|]*[\s]?)(.+)$" and,
enforces use of a Jira ticket number followed by a (space/|) and subject in lowercase.
For example, a valid subject would be "LA-1234 | fixes something" or "LA-1234 fixes something"

triage:
runs-on: "ubuntu-latest"
# Ignore dependabot branches
if: ! startsWith(github.event.pull_request.head.ref, 'dependabot/') && inputs.triage == 'true'

permissions:
contents: read
pull-requests: write
steps:
- name: Label PR
id: label-pr
uses: TimonVS/pr-labeler-action@v4.1.1
with:
repo-token: ${{ secrets.token }}
configuration-path: .github/pr-labels.yml

- name: Assign PR
id: assign-pr
uses: samspills/assign-pr-to-author@v1.0.2
with:
repo-token: "${{ secrets.token }}"
42 changes: 42 additions & 0 deletions pr-labels.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
# Label mappings for PRs
# Uses labels defined in .github/repo-labels.yml
# with branch name patterns defined in .github/workflows/pre-validate.yml
# Ref: https://github.com/marketplace/actions/pr-labeler
bug:
- "fix/*"
fix:
- "fix/*"
build:
- "build/*"
ci:
- "ci/*"
dependencies:
- "deps/*"
docs:
- "docs/*"
enhancement:
- "feat/*"
- "refactor/*"
- "perf/*"
github_actions:
- "ci/*"
perf:
- "perf/*"
python:
- "deps/*"
refactor:
- "refactor/*"
removal:
- "revert/*"
style:
- "style/*"
test:
- "test/*"
dependabot:
- "dependabot/*"
chore:
- "chore/*"
- "deps/*"
- "revert/*"
- "test/*"