diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d380258..2b88dc9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,6 +18,7 @@ on: - 'unpackaged/**' - 'pmd/**' - 'config/**' + - '**/workflows/**' # Jobs to be executed jobs: @@ -61,6 +62,34 @@ jobs: # run: npm run apex:local:stop pmd-analysis: + runs-on: ubuntu-latest + needs: format-lint + if: ${{ github.actor != 'dependabot[bot]' }} + steps: + # Checkout the source code + - name: 'Checkout source code' + uses: actions/checkout@v3 + + - uses: actions/setup-java@v3 + with: + distribution: 'temurin' + java-version: '11' + + - name: 'Perform PMD scan with PMD action' + uses: pmd/pmd-github-action@v1 + id: pmd-action + with: + version: 'latest' + sourcePath: 'force-app' + rulesets: 'pmd/deployRules.xml' + analyzeModifiedFilesOnly: false + createGitHubAnnotations: true + # Check for PMD violations + - name: 'Check for PMD violations' + if: steps.pmd-action.outputs.violations != 0 + run: exit 1 + + pmd-analysis-download: runs-on: ubuntu-latest needs: format-lint if: ${{ github.actor != 'dependabot[bot]' }} @@ -76,8 +105,8 @@ jobs: wget https://github.com/pmd/pmd/releases/download/pmd_releases%2F$PMD_VERSION/pmd-bin-$PMD_VERSION.zip unzip pmd-bin-$PMD_VERSION.zip -d ~ mv ~/pmd-bin-$PMD_VERSION ~/pmd - ~/pmd/bin/run.sh pmd --version + ~/pmd/bin/pmd --version # Run PMD scan - name: 'Run PMD scan' - run: ~/pmd/bin/run.sh pmd -d force-app -R pmd/deployRules.xml -f text --cache .pmdCache -min 2 + run: ~/pmd/bin/pmd check --dir force-app --rulesets pmd/deployRules.xml --format text --cache .pmdCache --no-progress --minimum-priority "Medium Low" \ No newline at end of file diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 7b9fb8a..b28b61b 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -10,34 +10,91 @@ on: - 'unpackaged/**' - 'pmd/**' - 'config/**' + - '**/workflows/**' workflow_dispatch: # Jobs to be executed jobs: - scratch-org-test: + format-check: runs-on: ubuntu-latest - #Choose the docker image from which the container should be created - container: - image: salesforce/salesforcedx:latest-full - options: --user 0:0 if: ${{ github.actor != 'dependabot[bot]' }} steps: # Checkout the source code - name: 'Checkout source code' uses: actions/checkout@v3 - # Install PMD - - name: 'Install Latest PMD' - run: | - PMD_VERSION=$(curl -s https://api.github.com/repos/pmd/pmd/releases/latest | grep '.tag_name' | sed 's:.*/::' | sed 's:",::') - echo $PMD_VERSION - wget https://github.com/pmd/pmd/releases/download/pmd_releases%2F$PMD_VERSION/pmd-bin-$PMD_VERSION.zip - unzip pmd-bin-$PMD_VERSION.zip -d ~ - mv ~/pmd-bin-$PMD_VERSION ~/pmd - ~/pmd/bin/run.sh pmd --version + # Install Volta to enforce proper node and package manager versions + - name: 'Install Volta' + uses: volta-cli/action@v4 + + # Cache node_modules to speed up the process + - name: 'Restore node_modules cache' + id: cache-npm + uses: actions/cache@v3 + with: + path: node_modules + key: npm-${{ hashFiles('**/package-lock.json') }} + restore-keys: | + npm-${{ env.cache-name }}- + npm- + # Install npm dependencies for Prettier and Jest + - name: 'Install npm dependencies' + if: steps.cache-npm.outputs.cache-hit != 'true' + run: npm ci + + # Prettier formatting + - name: 'Code formatting verification with Prettier' + run: npm run prettier:verify:apex + + scan-pmd-action: + runs-on: ubuntu-latest + needs: format-check + if: ${{ github.actor != 'dependabot[bot]' }} + steps: + # Checkout the source code + - name: 'Checkout source code' + uses: actions/checkout@v3 + - name: 'Setup java' + uses: actions/setup-java@v3 + with: + distribution: 'temurin' + java-version: '11' # Run PMD scan - - name: 'Run PMD scan' - run: ~/pmd/bin/run.sh pmd -d force-app -R pmd/deployRules.xml -f text --cache .pmdCache --minimum-priority 2 + - name: 'Perform PMD scan with PMD action' + uses: pmd/pmd-github-action@v1 + id: pmd-action + with: + version: 'latest' + sourcePath: 'force-app' + rulesets: 'pmd/deployRules.xml' + analyzeModifiedFilesOnly: false + createGitHubAnnotations: true + # Check for PMD violations + - name: 'Check for PMD violations' + if: steps.pmd-action.outputs.violations != 0 + run: exit 1 + + scratch-org-apex-tests: + runs-on: ubuntu-latest + needs: format-check + if: ${{ github.actor != 'dependabot[bot]' }} + steps: + # Checkout the source code + - name: 'Checkout source code' + uses: actions/checkout@v3 + + # Install Salesforce CLI + - name: 'Install Salesforce sfdx CLI' + run: | + npm install sfdx-cli --location=global + nodeInstallPath=$(npm config get prefix) + echo "$nodeInstallPath/bin" >> $GITHUB_PATH + sfdx --version + + - name: 'Install Salesforce sf CLI' + run: | + npm install @salesforce/cli --global + sf --version # Store secret for dev hub - name: 'Populate auth file with DEVHUB_SFDX_URL secret' @@ -49,31 +106,26 @@ jobs: echo "Missing DEVHUB_SFDX_URL secret. Is this workflow running on a fork?"; exit 1; fi - # Authenticate dev hub - name: 'Authenticate Dev Hub' - run: sfdx auth:sfdxurl:store -f ./DEVHUB_SFDX_URL.txt -a devhub -d + run: sf org login sfdx-url --sfdx-url-file ./DEVHUB_SFDX_URL.txt --alias devhub --set-default-dev-hub - # Add namespace to project config + # Add namespace to project config - name: Add namespace to project config run: | sed -i 's,"namespace": "","namespace": "",' sfdx-project.json # Create scratch org - name: 'Create scratch org' - run: sf env create scratch --definition-file config/project-scratch-def.json --alias CampaignMemberStatus --no-namespace --set-default --duration-days 3 --track-source --wait 20 + run: sf org create scratch --definition-file config/project-scratch-def.json --alias CampaignMemberStatus --set-default --no-ancestors --duration-days 1 --wait 20 --target-dev-hub devhub # Deploy source to scratch org - name: 'Push source to scratch org' - run: sfdx force:source:push - - # Assign permissionset - - name: 'Assign permissionset to default user' - run: sf org assign permset --name Campaign_Type_Member_Status_Admin --target-org CampaignMemberStatus + run: sf project deploy start # Run Apex tests in scratch org - name: 'Run Apex tests' - run: sfdx force:apex:test:run -c -r human -l RunLocalTests -w 20 -d ./tests/apex + run: sf apex run test --code-coverage --detailed-coverage --result-format human --wait 20 --test-level RunLocalTests --output-dir ./ # Upload code coverage to Codecov.io - name: 'Upload code coverage for Apex to Codecov.io' @@ -85,9 +137,9 @@ jobs: # Housekeeping - name: 'Delete scratch org' if: always() - run: sfdx force:org:delete -p -u CampaignMemberStatus + run: sf org delete scratch --no-prompt --target-org CampaignMemberStatus # Remove namespace from project config - name: Remove namespace from project config run: | - sed -i 's,"namespace": "","namespace": "",' sfdx-project.json + sed -i 's,"namespace": "","namespace": "",' sfdx-project.json \ No newline at end of file diff --git a/.github/workflows/release-please.yml b/.github/workflows/release-please.yml index 962ecbc..872d0f1 100644 --- a/.github/workflows/release-please.yml +++ b/.github/workflows/release-please.yml @@ -12,3 +12,4 @@ jobs: - uses: google-github-actions/release-please-action@v3 with: command: manifest + release-type: salesforce diff --git a/README.md b/README.md index e493b64..b044190 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,7 @@ ![Codecov](https://img.shields.io/codecov/c/github/dschach/campaign-member-status?logo=codecov) +[![PR Validation](https://github.com/dschach/campaign-member-status/actions/workflows/pr.yml/badge.svg)](https://github.com/dschach/campaign-member-status/actions/workflows/pr.yml) +[![On Push](https://github.com/dschach/campaign-member-status/actions/workflows/ci.yml/badge.svg)](https://github.com/dschach/campaign-member-status/actions/workflows/ci.yml) +[![release-please](https://github.com/dschach/campaign-member-status/actions/workflows/release-please.yml/badge.svg)](https://github.com/dschach/campaign-member-status/actions/workflows/release-please.yml) # Campaign Type Member Statuses