Skip to content

Commit

Permalink
build(GitHub): update workflows (#62)
Browse files Browse the repository at this point in the history
* build: workflows

* fix: run workflows when file updated

* fix: workflow path

* pmd changes
  • Loading branch information
dschach committed Apr 26, 2023
1 parent e9c0092 commit e999d96
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 30 deletions.
33 changes: 31 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ on:
- 'unpackaged/**'
- 'pmd/**'
- 'config/**'
- '**/workflows/**'

# Jobs to be executed
jobs:
Expand Down Expand Up @@ -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]' }}
Expand All @@ -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"
108 changes: 80 additions & 28 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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'
Expand All @@ -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
1 change: 1 addition & 0 deletions .github/workflows/release-please.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ jobs:
- uses: google-github-actions/release-please-action@v3
with:
command: manifest
release-type: salesforce
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down

0 comments on commit e999d96

Please sign in to comment.