diff --git a/.github/workflows/bash_unit.yml b/.github/workflows/bash_unit.yml new file mode 100644 index 0000000..6cb8e17 --- /dev/null +++ b/.github/workflows/bash_unit.yml @@ -0,0 +1,18 @@ +name: bash_unit Tests +on: + push: + branches: + - master + pull_request: + +jobs: + bash-unit-testing: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + ref: ${{ github.event.pull_request.head.sha }} + - name: Unit testing with bash_unit + run: | + curl -s https://raw.githubusercontent.com/pgrange/bash_unit/master/install.sh | bash + FORCE_COLOR=true ./bash_unit tests/test_* diff --git a/.github/workflows/linting.yml b/.github/workflows/linting.yml new file mode 100644 index 0000000..e15a20c --- /dev/null +++ b/.github/workflows/linting.yml @@ -0,0 +1,41 @@ +name: Linting + +# Always run on Pull Requests as then these checks can be marked as required. +on: + push: + branches: + - master + pull_request: + +permissions: {} + +jobs: + shell-check: + name: ShellCheck + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + ref: ${{ github.event.pull_request.head.sha }} + - name: Add error parser + run: echo -n "::add-matcher::shellcheck-matcher.json" + - name: Run ShellCheck + uses: ludeeus/action-shellcheck@2.0.0 + with: + format: gcc + + linting-summary: + name: Linting Summary + runs-on: ubuntu-22.04 + needs: [shell-check] + if: (!cancelled()) + steps: + - name: Check if any job failed + run: | + if [[ -z "$(echo "${{ join(needs.*.result, '') }}" | sed -e 's/success//g')" ]]; then + echo "All jobs succeeded" + else + echo "One or more jobs did not succeed" + exit 1 + fi diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..8a7c097 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,36 @@ +name: Test + +on: + push: + branches: + - master + pull_request: + +jobs: + test: + name: Test + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + - name: Test + id: test + uses: ./ + with: + commit-message: | + Use external action + + Run-GHA: true + Skip-PR-comments: true + Test-tag: always_passes,vm + + Required-githooks: true + + Signed-off-by: Brian J. Murrell + - name: Test value + run: | + set -eux + if [ '${{ env.CP_TEST_TAG }}' != 'always_passes,vm' ]; then + echo "Value is not 'always_passes,vm'" + exit 1 + fi diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..2403a00 --- /dev/null +++ b/LICENSE @@ -0,0 +1,51 @@ +Copyright 2021-2022 Intel Corporation. + +SPDX-License-Identifier: BSD-2-Clause-Patent + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +Subject to the terms and conditions of this license, each copyright holder +and contributor hereby grants to those receiving rights under this license +a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable +(except for failure to satisfy the conditions of this license) patent +license to make, have made, use, offer to sell, sell, import, and otherwise +transfer this software, where such license applies only to those patent +claims, already acquired or hereafter acquired, licensable by such copyright +holder or contributor that are necessarily infringed by: + +(a) their Contribution(s) (the licensed copyrights of copyright holders and + non-copyrightable additions of contributors, in source or binary form) + alone; or + +(b) combination of their Contribution(s) with the work of authorship to + which such Contribution(s) was added by such copyright holder or + contributor, if, at the time the Contribution is added, such addition + causes such combination to be necessarily infringed. The patent license + shall not apply to any other combinations which include the + Contribution. + +Except as expressly stated above, no rights or licenses from any copyright +holder or contributor is granted under this license, whether expressly, by +implication, estoppel or otherwise. + +DISCLAIMER + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..f89c3df --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +A GitHub Action to get the pragmas from a commit and import them into the environment prefixed with `CP_`. diff --git a/SECURITY.md b/SECURITY.md new file mode 100644 index 0000000..cb59eb8 --- /dev/null +++ b/SECURITY.md @@ -0,0 +1,5 @@ +# Security Policy +Intel is committed to rapidly addressing security vulnerabilities affecting our customers and providing clear guidance on the solution, impact, severity and mitigation. + +## Reporting a Vulnerability +Please report any security vulnerabilities in this project utilizing the guidelines [here](https://www.intel.com/content/www/us/en/security-center/vulnerability-handling-guidelines.html). diff --git a/action.yml b/action.yml new file mode 100644 index 0000000..ade0f23 --- /dev/null +++ b/action.yml @@ -0,0 +1,25 @@ +name: 'Import Commit Pragmas' +description: 'Import Commit Pragmas' +inputs: + commit-message: + description: 'Commit Message' + required: true +runs: + using: "composite" + steps: + # checkout the common library + - name: Checkout code + uses: actions/checkout@v4 + with: + repository: daos-stack/actions-lib + ref: v1 + path: actions-lib + - name: Import pragmas + id: import + shell: bash + run: | + set -eu + echo '${{ inputs.commit-message }}' | sed -e "s/'/'\"'\"'/g" | actions-lib/get_commit_pragmas | + sed -e 's/^/CP_/' >> $GITHUB_ENV + echo 'Identified pragmas:' + cat $GITHUB_ENV diff --git a/get_commit_pragmas b/get_commit_pragmas new file mode 100755 index 0000000..ddc96ff --- /dev/null +++ b/get_commit_pragmas @@ -0,0 +1,16 @@ +#!/bin/bash + +# NOTE: This is not actually used yet. +# Consumers of this function are getting it from actions-lib/gha_functions.sh until we can DRY the consumers out +# This will require one consumer to import a commit message and dequote it for all other users which is tricky +# due to the potential presence of both ' and " in commit messages +set -eu + +sed -Ene "s/'/'\"'\"'/g" \ + -e 's/^([-[:alnum:]]+): *([-<@>,\._ [:alnum:]]+)$/\1 \2/p' | + while read -r a b; do + echo -n "${a//-/_}" | tr '[:lower:]' '[:upper:]' + # escape special characters in the value + echo "=$b" | sed -e 's/\([<> ]\)/\\\1/g' + done | + sed -e 's/^/CP_/' diff --git a/shellcheck-matcher.json b/shellcheck-matcher.json new file mode 100644 index 0000000..1b8b487 --- /dev/null +++ b/shellcheck-matcher.json @@ -0,0 +1,17 @@ +{ + "problemMatcher": [ + { + "owner": "shellcheck-problem-matcher", + "severity": "error", + "pattern": [ + { + "regexp": "^(.*?):(\\d+):(\\d*):?\\s+(?:fatal\\s+)?(warning|error|note):\\s+(.*)$", + "file": 1, + "line": 2, + "column": 3, + "message": 5 + } + ] + } + ] +} diff --git a/tests/test_get_commit_pragmas b/tests/test_get_commit_pragmas new file mode 100755 index 0000000..79633cc --- /dev/null +++ b/tests/test_get_commit_pragmas @@ -0,0 +1,53 @@ +#!/bin/bash + +test_get_commit_pragmas() { + local msg='Use external action + +Run-GHA: true +Skip-PR-comments: true +Test-tag: always_passes,vm + +Required-githooks: true + +Signed-off-by: Brian J. Murrell +' + assert_equals "$(echo "$msg" | ../get_commit_pragmas)" 'CP_RUN_GHA=true +CP_SKIP_PR_COMMENTS=true +CP_TEST_TAG=always_passes,vm +CP_REQUIRED_GITHOOKS=true +CP_SIGNED_OFF_BY=Brian\ J.\ Murrell\ \' + + local msg='Escape spaces also + +'"'"'Will-not-be-a-pragma: false'"'"' should not be considered a commit +pragma, but: +Should-not-be-a-pragma: bar will be because it was not quoted. + +Skip-func-test-leap15: false +RPM-test-version: 2.5.100-13.10036.g65926e32 +Skip-PR-comments: true +Test-tag: always_passes always_fails +EL8-VM9-label: all_vm9 +EL9-VM9-label: all_vm9 +Leap15-VM9-label: all_vm9 +HW-medium-label: new_icx5 +HW-large-label: new_icx9 + +Required-githooks: true + +Signed-off-by: Brian J. Murrell +' + assert_equals "$(echo "$msg" | ../get_commit_pragmas)" 'CP_SHOULD_NOT_BE_A_PRAGMA=bar\ will\ be\ because\ it\ was\ not\ quoted. +CP_SKIP_FUNC_TEST_LEAP15=false +CP_RPM_TEST_VERSION=2.5.100-13.10036.g65926e32 +CP_SKIP_PR_COMMENTS=true +CP_TEST_TAG=always_passes\ always_fails +CP_EL8_VM9_LABEL=all_vm9 +CP_EL9_VM9_LABEL=all_vm9 +CP_LEAP15_VM9_LABEL=all_vm9 +CP_HW_MEDIUM_LABEL=new_icx5 +CP_HW_LARGE_LABEL=new_icx9 +CP_REQUIRED_GITHOOKS=true +CP_SIGNED_OFF_BY=Brian\ J.\ Murrell\ \' + +}