|
| 1 | +# stub to call common GitHub Action (GA) as part of Continuous Integration (CI) Pull Request process checks for main branch |
| 2 | +# inputs are described in the chef/common-github-actions/<GA.yml> with same name as this stub |
| 3 | +# |
| 4 | +# secrets are inherited from the calling workflow, typically SONAR_TOKEN, SONAR_HOST_URL, GH_TOKEN, AKEYLESS_JWT_ID, POLARIS_SERVER_URL and POLARIS_ACCESS_TOKEN |
| 5 | + |
| 6 | +name: CI Pull Request on Main Branch |
| 7 | + |
| 8 | +on: |
| 9 | + pull_request: |
| 10 | + branches: [ main, release/** ] |
| 11 | + push: |
| 12 | + branches: [ main, release/** ] |
| 13 | + |
| 14 | + workflow_dispatch: |
| 15 | + |
| 16 | +permissions: |
| 17 | + contents: read |
| 18 | + |
| 19 | +env: |
| 20 | + STUB_VERSION: "1.0.8" |
| 21 | + |
| 22 | +jobs: |
| 23 | + echo_version: |
| 24 | + name: 'Echo stub version' |
| 25 | + runs-on: ubuntu-latest |
| 26 | + steps: |
| 27 | + - name: echo version of stub and inputs |
| 28 | + run: | |
| 29 | + echo "CI main pull request stub version $STUB_VERSION" |
| 30 | +
|
| 31 | + detect-custom-metadata: |
| 32 | + name: 'Detect custom properties' |
| 33 | + runs-on: ubuntu-latest |
| 34 | + outputs: |
| 35 | + primaryApplication: ${{ steps.set-custom-metadata.outputs.primaryApplication }} |
| 36 | + appBuildLanguage: ${{ steps.set-custom-metadata.outputs.applicationBuildLanguage }} |
| 37 | + appBuildProfile: ${{ steps.set-custom-metadata.outputs.applicationBuildProfile }} |
| 38 | + versionFromFile: ${{ steps.set-version-from-file.outputs.versionFromFile }} |
| 39 | + steps: |
| 40 | + - name: 'Checkout repository' |
| 41 | + uses: actions/checkout@v4 |
| 42 | + |
| 43 | + - name: 'Detect version from file' |
| 44 | + id: set-version-from-file |
| 45 | + shell: bash |
| 46 | + run: | |
| 47 | + if [[ -f "VERSION" ]]; then |
| 48 | + version=$(head -1 VERSION) |
| 49 | + echo "VERSION_FROM_FILE=${version}" >> $GITHUB_ENV |
| 50 | + echo "versionFromFile=${version}" >> $GITHUB_OUTPUT |
| 51 | + elif [[ -f "go.mod" ]]; then |
| 52 | + version=$(grep -Eo 'v[0-9]+\.[0-9]+\.[0-9]+' go.mod | head -1) |
| 53 | + echo "VERSION_FROM_FILE=${version}" >> $GITHUB_ENV |
| 54 | + echo "versionFromFile=${version}" >> $GITHUB_OUTPUT |
| 55 | + else |
| 56 | + echo "VERSION_FROM_FILE not found, defaulting to empty" |
| 57 | + echo "versionFromFile=" >> $GITHUB_OUTPUT |
| 58 | + fi |
| 59 | + # do not do echo "::set-output name=versionFromFile::$version" any more per https://github.blog/changelog/2022-10-11-github-actions-deprecating-save-state-and-set-output-commands/ |
| 60 | + |
| 61 | + - name: 'Detect app, language, and build profile environment variables from repository custom properties' |
| 62 | + id: set-custom-metadata |
| 63 | + # GH API returns something like [{"property_name":"GABuildLanguage","value":"go"},{"property_name":"GABuildProfile","value":"cli"},{"property_name":"primaryApplication","value":"chef-360"}]' |
| 64 | + run: | |
| 65 | + response=$(gh api -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" /repos/${{ github.repository }}/properties/values) |
| 66 | +
|
| 67 | + primaryApplication=$(echo "$response" | jq -r '.[] | select(.property_name=="primaryApplication") | .value') |
| 68 | + GABuildLanguage=$(echo "$response" | jq -r '.[] | select(.property_name=="GABuildLanguage") | .value') |
| 69 | + GABuildProfile=$(echo "$response" | jq -r '.[] | select(.property_name=="GABuildProfile") | .value') |
| 70 | + |
| 71 | + echo "PRIMARY_APPLICATION=$primaryApplication" >> $GITHUB_ENV |
| 72 | + echo "GA_BUILD_LANGUAGE=$GABuildLanguage" >> $GITHUB_ENV |
| 73 | + echo "GA_BUILD_PROFILE=$GABuildProfile" >> $GITHUB_ENV |
| 74 | +
|
| 75 | + # If workflow_dispatch, use inputs (left), if other trigger, use default env (right) |
| 76 | + echo "primaryApplication=${primaryApplication}" >> $GITHUB_OUTPUT |
| 77 | + echo "applicationBuildLanguage=${GABuildLanguage}" >> $GITHUB_OUTPUT |
| 78 | + echo "applicationBuildProfile=${GABuildProfile}" >> $GITHUB_OUTPUT |
| 79 | + continue-on-error: true |
| 80 | + env: |
| 81 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 82 | + |
| 83 | + call-ci-main-pr-check-pipeline: |
| 84 | + uses: chef/common-github-actions/.github/workflows/ci-main-pull-request.yml@main |
| 85 | + # needs: [detect-custom-metadata, detect-version-from-file] |
| 86 | + needs: [detect-custom-metadata] |
| 87 | + secrets: inherit |
| 88 | + permissions: |
| 89 | + id-token: write |
| 90 | + contents: read |
| 91 | + |
| 92 | + with: |
| 93 | + application: ${{ needs.detect-custom-metadata.outputs.primaryApplication }} |
| 94 | + visibility: ${{ github.event.repository.visibility }} # private, public, or internal |
| 95 | + # go-private-modules: GOPRIVATE for Go private modules, default is 'github.com/progress-platform-services/* |
| 96 | + |
| 97 | + # if version specified, it takes precedence; can be a semver like 1.0.2-xyz or a tag like "latest" |
| 98 | + version: ${{ needs.detect-custom-metadata.outputs.versionFromFile || '1.0.0' }} |
| 99 | + detect-version-source-type: 'file' # options include "none" (do not detect), "file", "github-tag" or "github-release" |
| 100 | + detect-version-source-parameter: '' # use for file name |
| 101 | + language: ${{ needs.detect-custom-metadata.outputs.appBuildLanguage }} # Go, Ruby, Rust, JavaScript, TypeScript, Python, Java, C#, PHP, other - used for build and SonarQube language setting |
| 102 | + |
| 103 | + # complexity-checks, linting, trufflehog and trivy |
| 104 | + perform-complexity-checks: true |
| 105 | + # scc-output-filename: 'scc-output.txt' |
| 106 | + perform-language-linting: true # Perform language-specific linting and pre-compilation checks |
| 107 | + perform-trufflehog-scan: true |
| 108 | + perform-trivy-scan: true |
| 109 | + |
| 110 | + # perform application build and unit testing, will use custom repository properties when implemented for chef-primary-application, chef-build-profile, and chef-build-language |
| 111 | + build: true |
| 112 | + build-profile: ${{ needs.detect-custom-metadata.outputs.appBuildProfile }} |
| 113 | + unit-tests: false |
| 114 | + unit-test-output-path: "path/to/file.out" |
| 115 | + unit-test-command-override: "" |
| 116 | + |
| 117 | + # BlackDuck SAST (Polaris) require a build or binary present in repo to do SAST testing |
| 118 | + # requires these secrets: POLARIS_SERVER_URL, POLARIS_ACCESS_TOKEN |
| 119 | + perform-blackduck-polaris: false |
| 120 | + polaris-application-name: "Chef-Agents" # one of these: Chef-Agents, Chef-Automate, Chef-Chef360, Chef-Habitat, Chef-Infrastructure-Server, Chef-Shared-Services, Chef-Other, Chef-Non-Product |
| 121 | + polaris-project-name: ${{ github.event.repository.name }} # arch-sample-cli |
| 122 | + polaris-working-directory: '.' # Working directory for the scan, defaults to . but usually lang-dependent like ./src |
| 123 | + polaris-coverity-build-command: 'go build -o bin/chef-cli.exe' # Coverity build command, typically done in build stage by language or here as param 1-liner like "mvn clean install" |
| 124 | + polaris-coverity-clean-command: 'go clean' # Coverity clean command, typically done before build stage by language or here as param 1-liner like "mvn clean" |
| 125 | + polaris-detect-search-depth: '5' # Detect search depth, blank but can be set to "3" to search up to 3 levels of subdirectories for code to scan' |
| 126 | + polaris-assessment-mode: 'SAST' # Assessment mode (SAST, CI or SOURCE_UPLOAD) |
| 127 | + wait-for-scan: true |
| 128 | + # polaris-detect-args: '' # Additional Detect arguments, can supply extra arguments like "--detect.diagnostic=true" |
| 129 | + # coverity_build_command: "go build" |
| 130 | + # coverity_clean_command: "go clean" |
| 131 | + # polaris-config-path: '' # Path to Detect configuration file, typically a file supplied at root level like ./detect-config.yml |
| 132 | + # polaris-coverity-config-path: '' # Path to Coverity configuration file, typically a file supplied at root level like ./coverity.yml |
| 133 | + # polaris-coverity-args: '' # Additional Coverity arguments,can supply extra arguments like "--config-override capture.build.build-command=make |
| 134 | + |
| 135 | + # perform SonarQube scan, with or without unit test coverage data |
| 136 | + # requires secrets SONAR_TOKEN and SONAR_HOST_URL (progress.sonar.com) |
| 137 | + perform-sonarqube-scan: true |
| 138 | + # perform-sonar-build: true |
| 139 | + # build-profile: 'default' |
| 140 | + # report-unit-test-coverage: true |
| 141 | + perform-docker-scan: false # scan Dockerfile and built images with Docker Scout or Trivy; see repo custom properties matching "container" |
| 142 | + |
| 143 | + # report to central developer dashboard |
| 144 | + report-to-atlassian-dashboard: false |
| 145 | + quality-product-name: 'Chef-Agents' # product name for quality reporting, like Chef360, Courier, Inspec |
| 146 | + # quality-product-name: ${{ github.event.repository.name }} # like 'Chef-360' - the product name for quality reporting, like Chef360, Courier, Inspec |
| 147 | + # quality-sonar-app-name: 'YourSonarAppName' |
| 148 | + # quality-testing-type: 'Integration' like Unit, Integration, e2e, api, Performance, Security |
| 149 | + # quality-service-name: 'YourServiceOrRepoName' |
| 150 | + # quality-junit-report: 'path/to/junit/report'' |
| 151 | + |
| 152 | + # perform Habitat-based and native packaging, publish to package repositories |
| 153 | + package-binaries: false # Package binaries (e.g., RPM, DEB, MSI, dpkg + signing + SHA) |
| 154 | + habitat-build: false # Create Habitat packages |
| 155 | + publish-habitat-packages: false # Publish Habitat packages to Builder |
| 156 | + publish-habitat-hab_package: false # Chef Habitat package to install (e.g., core/nginx) |
| 157 | + publish-habitat-hab_version: "1.0.0" # Chef Habitat package version (optional) |
| 158 | + publish-habitat-hab_release: "20240101010101" # Chef Habitat package release (optional) |
| 159 | + publish-habitat-hab_channel: "stable" # Chef Habitat package channel (e.g., stable, base, base-2025); default is stable |
| 160 | + publish-habitat-hab_auth_token: "" # Chef Habitat Builder authentication token (uses secret if not provided) |
| 161 | + publish-habitat-runner_os: "ubuntu-latest" # OS runner for Habitat package publishing job, can also be windows-latest |
| 162 | + habitat-grype-scan: false # Scan built Habitat packages with Grype for vulnerabilities |
| 163 | + publish-packages: false # Publish packages (e.g., container from Dockerfile to ECR, go-releaser binary to releases page, omnibus to artifactory, gems, choco, homebrew, other app stores) |
| 164 | + |
| 165 | + # generate and export Software Bill of Materials (SBOM) in various formats |
| 166 | + generate-sbom: true |
| 167 | + export-github-sbom: true # SPDX JSON artifact on job instance |
| 168 | + generate-msft-sbom: false |
| 169 | + license_scout: false # Run license scout for license compliance (uses .license_scout.yml) |
| 170 | + |
| 171 | + # perform Blackduck software composition analysis (SCA) for 3rd party CVEs, licensing, and operational risk |
| 172 | + perform-blackduck-sca-scan: true # combined with generate sbom & generate github-sbom, also needs version above |
| 173 | + blackduck-project-group-name: 'Chef-Agents' # typically one of (Chef), Chef-Agents, Chef-Automate, Chef-Chef360, Chef-Habitat, Chef-Infrastructure-Server, Chef-Shared-Services, Chef-Non-Product' |
| 174 | + blackduck-project-name: ${{ github.event.repository.name }} # BlackDuck project name, typically the repository name |
| 175 | + blackduck-force-low-accuracy-mode: false # if true, forces BlackDuck Detect to run in low accuracy mode which can reduce scan time for large projects at the cost of potentially missing some vulnerabilities; see https://synopsys.atlassian.net/wiki/spaces/INTDOCS/pages/1138617921/Black+Duck+Detect+Accuracy+Levels for details |
| 176 | + |
| 177 | + # udf1: 'default' # user defined flag 1 |
| 178 | + # udf2: 'default' # user defined flag 2 |
| 179 | + # udf3: 'default' # user defined flag 3 |
0 commit comments