From 0a551385ecf45e4fcb7ef617ae6476a47a3171e8 Mon Sep 17 00:00:00 2001 From: BryanQuigley Date: Tue, 27 Sep 2022 10:05:38 -0700 Subject: [PATCH] Add examples for using a shared env file and related STRTA scripts (#3351) This adds 4 example files to the local README to do a shared env file. This is much simpler then adding support directly that I tried in PR #3270. Fixes: #2851 --- docs/run-linter-locally.md | 63 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/docs/run-linter-locally.md b/docs/run-linter-locally.md index 78e697df..808a70de 100644 --- a/docs/run-linter-locally.md +++ b/docs/run-linter-locally.md @@ -34,6 +34,69 @@ You can follow the link below on how to install and configure **Docker** on your You can add as many **Additional** flags as needed, documented in [README.md](../README.md#Environment-variables) +## Sharing Environment variables between Local and CI + +If you run both locally and on CI it's very helpful to only have to define your env variables once. This is one setup using Github's [STRTA](https://github.com/github/scripts-to-rule-them-all) style to do so. + +### .github/super-linter.env + +This is the shared location for the super-linter variables. Example: + +```bash +VALIDATE_ALL_CODEBASE=true +VALIDATE_DOCKERFILE_HADOLINT=false +VALIDATE_EDITORCONFIG=false +VALIDATE_GITLEAKS=false +``` + +### scripts/lint + +This always runs the local docker based linting. + +```bash +docker run --rm \ + -e RUN_LOCAL=true \ + --env-file ".github/super-linter.env" \ + -v "$PWD":/tmp/lint github/super-linter:v4 +``` + +### scripts/test + +This runs the local lint when not on CI. + +```bash +if [ "$(whoami)" == "runner" ]; then + echo "We are on GitHub, so don't run lint manually" +else + echo "Running locally because we don't think we are on GitHub" + lint_ci +fi +``` + +### .github/workflows/ci.yml + +This loads the environment variables before running the GitHub Actions job. + +```yaml +name: CI + +on: + pull_request: + +jobs: + lint: + # Run GH Super-Linter against code base + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - run: cat .github/super-linter.env >> "$GITHUB_ENV" + - name: Lint Code Base + uses: github/super-linter@v4 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + DEFAULT_BRANCH: develop +``` + ## Troubleshooting ### Run container and gain access to the command-line