From 348cfa62a86101d40537efb0e293b9ca07a24d84 Mon Sep 17 00:00:00 2001 From: Theodore Georgomanolis Date: Wed, 10 Aug 2022 16:24:29 +0300 Subject: [PATCH] feat: initial GH action commit --- .dockerignore | 5 +++ .gitattributes | 7 +++ .github/CODEOWNERS | 4 ++ .github/dependabot.yml | 11 +++++ .github/pull_request_template.md | 7 +++ .github/workflows/release.yml | 32 ++++++++++++++ .github/workflows/shellcheck.yml | 13 ++++++ .gitignore | 11 +++++ CODE_OF_CONDUCT.md | 76 ++++++++++++++++++++++++++++++++ CONTRIBUTING.md | 6 +++ Dockerfile | 8 ++++ README.md | 23 +++++++++- action.yml | 30 +++++++++++++ entrypoint.sh | 73 ++++++++++++++++++++++++++++++ 14 files changed, 305 insertions(+), 1 deletion(-) create mode 100644 .dockerignore create mode 100644 .gitattributes create mode 100644 .github/CODEOWNERS create mode 100644 .github/dependabot.yml create mode 100644 .github/pull_request_template.md create mode 100644 .github/workflows/release.yml create mode 100644 .github/workflows/shellcheck.yml create mode 100644 .gitignore create mode 100644 CODE_OF_CONDUCT.md create mode 100644 CONTRIBUTING.md create mode 100644 Dockerfile create mode 100644 action.yml create mode 100644 entrypoint.sh diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..dc0e549 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,5 @@ +# Exclude everything +* + +# Allow +!entrypoint.sh diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..3b3d94a --- /dev/null +++ b/.gitattributes @@ -0,0 +1,7 @@ +* text=auto + +*.md text +*.yaml text +*.yml text +*.sh eol=lf +Dockerfile text diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 0000000..f44a682 --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1,4 @@ +# These owners will be the default owners for everything in +# the repo. +# +* @theodore86 diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..aea4a17 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,11 @@ +version: 2 +updates: + - package-ecosystem: "docker" + directory: "/" + schedule: + interval: "daily" + + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "daily" diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md new file mode 100644 index 0000000..5a1b461 --- /dev/null +++ b/.github/pull_request_template.md @@ -0,0 +1,7 @@ + +## Description + + +#### Related Issues + +Addresses diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..4ac1b9c --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,32 @@ +--- +name: "Production release" +on: + push: + tags: + - "v[0-9]+.[0-9]+.[0-9]+" +jobs: + build: + name: 'Create Release' + runs-on: ubuntu-latest + steps: + - name: 'Checkout code' + uses: 'actions/checkout@v3.0.2' + + - name: 'Produce release body' + id: 'git_log' + uses: 'beatlabs/release-changelog-action@v0.0.4' + with: + tag_regex: "v[0-9]+.[0-9]+.[0-9]+" + + - name: 'Create release' + id: 'create_release' + uses: 'actions/create-release@v1.1.4' + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: ${{ github.ref }} + release_name: ${{ github.ref }} + body: ${{ steps.git_log.outputs.release_body }} + draft: false + prerelease: false +... diff --git a/.github/workflows/shellcheck.yml b/.github/workflows/shellcheck.yml new file mode 100644 index 0000000..b1ce1d3 --- /dev/null +++ b/.github/workflows/shellcheck.yml @@ -0,0 +1,13 @@ +name: Shellcheck +on: + pull_request: + paths: + - '**.sh' + +jobs: + shellcheck: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Run ShellCheck + uses: ludeeus/action-shellcheck@1.1.0 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..46f42f8 --- /dev/null +++ b/.gitignore @@ -0,0 +1,11 @@ +CMakeLists.txt.user +CMakeCache.txt +CMakeFiles +CMakeScripts +Testing +Makefile +cmake_install.cmake +install_manifest.txt +compile_commands.json +CTestTestfile.cmake +_deps diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 0000000..7c65511 --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1,76 @@ +# Contributor Covenant Code of Conduct + +## Our Pledge + +In the interest of fostering an open and welcoming environment, we as +contributors and maintainers pledge to making participation in our project and +our community a harassment-free experience for everyone, regardless of age, body +size, disability, ethnicity, sex characteristics, gender identity and expression, +level of experience, education, socio-economic status, nationality, personal +appearance, race, religion, or sexual identity and orientation. + +## Our Standards + +Examples of behavior that contributes to creating a positive environment +include: + +* Using welcoming and inclusive language +* Being respectful of differing viewpoints and experiences +* Gracefully accepting constructive criticism +* Focusing on what is best for the community +* Showing empathy towards other community members + +Examples of unacceptable behavior by participants include: + +* The use of sexualized language or imagery and unwelcome sexual attention or + advances +* Trolling, insulting/derogatory comments, and personal or political attacks +* Public or private harassment +* Publishing others' private information, such as a physical or electronic + address, without explicit permission +* Other conduct which could reasonably be considered inappropriate in a + professional setting + +## Our Responsibilities + +Project maintainers are responsible for clarifying the standards of acceptable +behavior and are expected to take appropriate and fair corrective action in +response to any instances of unacceptable behavior. + +Project maintainers have the right and responsibility to remove, edit, or +reject comments, commits, code, wiki edits, issues, and other contributions +that are not aligned to this Code of Conduct, or to ban temporarily or +permanently any contributor for other behaviors that they deem inappropriate, +threatening, offensive, or harmful. + +## Scope + +This Code of Conduct applies both within project spaces and in public spaces +when an individual is representing the project or its community. Examples of +representing a project or community include using an official project e-mail +address, posting via an official social media account, or acting as an appointed +representative at an online or offline event. Representation of a project may be +further defined and clarified by project maintainers. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be +reported by contacting the project team members (@hwoarang). +All complaints will be reviewed and investigated and will result in a response that +is deemed necessary and appropriate to the circumstances. The project team is +obligated to maintain confidentiality with regard to the reporter of an incident. +Further details of specific enforcement policies may be posted separately. + +Project maintainers who do not follow or enforce the Code of Conduct in good +faith may face temporary or permanent repercussions as determined by other +members of the project's leadership. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, +available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html + +[homepage]: https://www.contributor-covenant.org + +For answers to common questions about this code of conduct, see +https://www.contributor-covenant.org/faq diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..9a199fc --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,6 @@ +# Contributing to this project + +- Create your feature branch. +- Make your changes +- Open a pull request. +- Make sure that CI tests are passing. diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..e21dfea --- /dev/null +++ b/Dockerfile @@ -0,0 +1,8 @@ +FROM quay.io/coreos/po-tooling:release-0.48 +LABEL maintainer="t.georgomanolis@thebeat.co" + +WORKDIR /app +COPY entrypoint.sh . +RUN chmod +x entrypoint.sh + +ENTRYPOINT ["/app/entrypoint.sh"] diff --git a/README.md b/README.md index f0023e3..c3e79da 100644 --- a/README.md +++ b/README.md @@ -1 +1,22 @@ -# prometheus-operator-github-action \ No newline at end of file +# Prometheus Operator GitHub Action + +## Introduction +This simple GitHub Action allows to run [po-lint](https://github.com/prometheus-operator/prometheus-operator/blob/main/Documentation/user-guides/linting.md) on kubernetes [prometheus operator](https://github.com/prometheus-operator/prometheus-operator) CRDs. + +## Usage +```yaml +name: Check PrometheusRule CRDs +on: + pull_request: + +jobs: + polint: + name: Prometheus operator lint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: taxibeat/prometheus-operator-github-action@v1 + with: + path: './rules' + exclude: '.*test.*' +``` diff --git a/action.yml b/action.yml new file mode 100644 index 0000000..8982a2c --- /dev/null +++ b/action.yml @@ -0,0 +1,30 @@ +--- +name: 'Prometheus Operator (Lint) Github Action' +description: 'Run po-lint (linting) against PrometheusRules CRDs' +author: 'Theodore Georgomanolis' +inputs: + path: + description: 'Path to Prometheus operator rules' + required: false + default: './' + glob_pattern: + description: 'Rule file extension as glob pattern' + required: false + default: '*.y*ml' + exclude: + description: 'Regex to exclude files or folders from linting' + required: false + default: '' + +runs: + using: 'docker' + image: 'Dockerfile' + args: + - ${{ inputs.path }} + - ${{ inputs.global_pattern }} + - ${{ inputs.exclude }} + +branding: + icon: 'terminal' + color: 'blue' +... diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 0000000..e42d327 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,73 @@ +#!/usr/bin/env bash +set -o noglob + +error() { + echo >&2 ":: [Error]: $*" + exit 1 +} + +info() { + echo >&1 ":: [Info]: $*" + return 0 +} + +_command() { + local _return cmd + cmd="$1" + _return=1 + command -v "$cmd" >/dev/null && _return=0 + return ${_return} +} + +# shellcheck disable=SC2086 +_find() { + local path="$1" + local glob_pattern="${2:-*.y*ml}" + local cmd="$path -name ${glob_pattern}" + local files + files="$(find $cmd)" + echo "$files" +} + +_check() { + local files="$1" + local exclude="${2:-""}" + local errors=0 + for file in $files; do + if [[ -n $exclude ]]; then + if echo "$file" | grep -Eq "$exclude"; then + info "Skipping file: $file" + continue + fi + fi + info "Checking file: $file" + if ! '/go/bin/po-lint' "$file"; then + ((errors+=1)) + fi + done + return $errors +} + +lint() { + local path="$1" + local glob_pattern="${2:-*.y*ml}" + local exclude="${3:-""}" + _command '/go/bin/po-lint' || error "'po-lint' linter not installed" + local files + files=$(_find "$path" "${glob_pattern}") + info "Linting '${glob_pattern}' files in '${path}' directory" + _check "$files" "$exclude" +} + +main() { + local path="$1" + local glob_pattern="${2:-*.y*ml}" + local exclude="${3:-""}" + [[ ! -d $path ]] && error "$path directory not found" + if ! lint "$path" "${glob_pattern}" "$exclude"; then + error "Linting failed" + fi + info "Linting succeded" +} + +main "$@"