Skip to content

Commit

Permalink
Repackages individual Actions (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
ubiratansoares authored May 20, 2024
1 parent 6955e19 commit 8ed024d
Show file tree
Hide file tree
Showing 14 changed files with 149 additions and 66 deletions.
18 changes: 14 additions & 4 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,24 @@ on:
- main

jobs:
checks:
component-tests:
runs-on: ubuntu-22.04

steps:
- name: Checkout code
- name: Checkout source
uses: actions/[email protected]

- name: Component tests for essential checks
uses: ./essentials
- name: Check typos on source files and docs
uses: ./quality/typos

- name: Lint Bash scripts
uses: ./quality/bash

- name: Lint Markdown files
uses: ./quality/markdown

- name: Check MIT license on source files
uses: ./foss/check-licenses
with:
file-patterns: "*.sh"
license: "mit"
4 changes: 2 additions & 2 deletions .mergify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ pull_request_rules:
- name: Automatic merge for Renovate PRs
conditions:
- author~=^renovate\[bot\]$
- check-success=checks
- check-success=component-tests
actions:
merge:
method: squash

- name: Be author's friend
conditions:
- author~=ubiratansoares
- check-success=checks
- check-success=component-tests
actions:
merge:
method: squash
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2023 Dotanuki Labs
Copyright (c) 2024 Dotanuki Labs

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ Reusable CI/CD logic targeting pipelines on Github Actions

## License

Copyright (c) 2023 - Dotanuki Labs - [The MIT license](https://choosealicense.com/licenses/mit/)
Copyright (c) 2024 - Dotanuki Labs - [The MIT license](https://choosealicense.com/licenses/mit/)
30 changes: 0 additions & 30 deletions essentials/action.yaml

This file was deleted.

18 changes: 18 additions & 0 deletions foss/check-licenses/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: "check-licenses"
description: "Check open-source licence on source code headers"

inputs:
file-patterns:
description: “Patterns to look in source files, comma separated”
required: true

license:
description: “Open-source license to enforce”
required: true

runs:
using: "composite"
steps:
- name: Check licenses on source files
shell: bash
run: ${{ github.action_path }}/license-checker.sh $GITHUB_WORKSPACE ${{ inputs.file-patterns }} ${{ inputs.license }}
19 changes: 15 additions & 4 deletions src/license-enforcer.sh → foss/check-licenses/license-checker.sh
Original file line number Diff line number Diff line change
@@ -1,22 +1,33 @@
#!/usr/bin/env bash
# Copyright 2023 Dotanuki Labs
# Copyright 2024 Dotanuki Labs
# SPDX-License-Identifier: MIT

# shellcheck disable=SC1091
# shellcheck disable=SC2046

set -eo pipefail

current_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "$current_dir/lib/preconditions.sh"

# https://github.com/google/addlicense
readonly addlicense="ghcr.io/google/addlicense"

readonly target_folder="$1"
readonly sources="$2"
readonly license="$3"

require_docker_daemon() {
if (! docker stats --no-stream >/dev/null); then
echo "Docker is required for this execution"
echo
exit 1
fi
}

require_docker_image() {
local image_spec="$1"
echo "Pulling Docker image : $image_spec"
docker pull "$image_spec" >/dev/null 2>&1
}

check_license_on_files() {
local extension="$1"

Expand Down
9 changes: 9 additions & 0 deletions quality/bash/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name: "bash-linter"
description: "Lint all Bash scripts"

runs:
using: "composite"
steps:
- name: Lint Bash Scripts
shell: bash
run: ${{ github.action_path }}/bash-linter.sh $GITHUB_WORKSPACE
19 changes: 15 additions & 4 deletions src/bash-linter.sh → quality/bash/bash-linter.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
#!/usr/bin/env bash
# Copyright 2023 Dotanuki Labs
# Copyright 2024 Dotanuki Labs
# SPDX-License-Identifier: MIT

# shellcheck disable=SC1091

set -eo pipefail

current_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "$current_dir/lib/preconditions.sh"

# https://github.com/mvdan/sh
readonly shmft="docker.io/mvdan/shfmt:latest"

Expand All @@ -17,6 +14,20 @@ readonly shellcheck="docker.io/koalaman/shellcheck-alpine:stable"

readonly target_folder="$1"

require_docker_daemon() {
if (! docker stats --no-stream >/dev/null); then
echo "Docker is required for this execution"
echo
exit 1
fi
}

require_docker_image() {
local image_spec="$1"
echo "Pulling Docker image : $image_spec"
docker pull "$image_spec" >/dev/null 2>&1
}

check_code_style() {
echo "→ Checking code formatting (shfmt)"
docker run --rm -v "$target_folder:/mnt" -w /mnt "$shmft" --diff .
Expand Down
9 changes: 9 additions & 0 deletions quality/markdown/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name: "markdown-linter"
description: "Check structure for markdown file and enforce valid links"

runs:
using: "composite"
steps:
- name: Lint Markdown files
shell: bash
run: ${{ github.action_path }}/markdown-linter.sh $GITHUB_WORKSPACE
56 changes: 56 additions & 0 deletions quality/markdown/markdown-linter.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/usr/bin/env bash
# Copyright 2024 Dotanuki Labs
# SPDX-License-Identifier: MIT

# shellcheck disable=SC1091

set -eo pipefail

readonly target_folder="$1"

# https://github.com/igorshubovych/markdownlint-cli
readonly markdownlint="ghcr.io/igorshubovych/markdownlint-cli:latest"

# https://github.com/lycheeverse/lychee
readonly lychee="lycheeverse/lychee:latest"

require_docker_daemon() {
if (! docker stats --no-stream >/dev/null); then
echo "Docker is required for this execution"
echo
exit 1
fi
}

require_docker_image() {
local image_spec="$1"
echo "Pulling Docker image : $image_spec"
docker pull "$image_spec" >/dev/null 2>&1
}

lint_markdown() {
echo
echo "→ Linting markdown files (markdownlint)"
docker run --rm -v "$target_folder:/workdir" "$markdownlint" "**/*.md"
}

check_broken_links() {
echo
echo "→ Checking broken links (lychee)"
docker run --rm -w /input -v "$target_folder:/input" "$lychee" "**/*.md"
}

echo
echo "🔥 Linting Markdown files"
echo

require_docker_daemon
require_docker_image "$markdownlint"
require_docker_image "$lychee"

lint_markdown
check_broken_links

echo
echo "✅ All good!"
echo
8 changes: 8 additions & 0 deletions quality/typos/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
name: "typos-checker"
description: "Inspect source files for typos and spelling"

runs:
using: "composite"
steps:
- name: Check typos everywhere
uses: crate-ci/[email protected]
2 changes: 1 addition & 1 deletion src/docs-linter.sh → quality/typos/typos-checker.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env bash
# Copyright 2023 Dotanuki Labs
# Copyright 2024 Dotanuki Labs
# SPDX-License-Identifier: MIT

# shellcheck disable=SC1091
Expand Down
19 changes: 0 additions & 19 deletions src/lib/preconditions.sh

This file was deleted.

0 comments on commit 8ed024d

Please sign in to comment.