Skip to content

Commit

Permalink
Update sfdx to sf (#21)
Browse files Browse the repository at this point in the history
* Switch to SF from SFDX

* fix cmdln switch

* sf scanner

* clean up

* Update README
  • Loading branch information
nigelhu authored Oct 19, 2023
1 parent 5b0b4e0 commit 804ce25
Show file tree
Hide file tree
Showing 12 changed files with 10,480 additions and 22,474 deletions.
37 changes: 23 additions & 14 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ on:
jobs:
# This workflow contains a single job called "build"
build:
env:
NODE_VERSION: 18
PMD_RULESET_FILE: "./pmd-apex-ruleset.xml"
PMD_RESULT_FILE: "./pmd-result.xml"
ORG_ALIAS: "sfdx-example"
ADMIN_EMAIL: "merv@merv.org.uk"

# The type of runner that the job will run on
runs-on: ubuntu-latest

Expand All @@ -25,43 +32,45 @@ jobs:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v3

# RUN PMD ~ pmd -language apex -d . -R pmd-apex-ruleset.xml -f text --failOnViolation false
- name: Run PMD
uses: sfdx-actions/setup-pmd@v1
- run: pmd -language apex -d . -R pmd-apex-ruleset.xml -f text -min 1 -no-cache
- run: pmd -language apex -d . -R pmd-apex-ruleset.xml -f text --failOnViolation false -min 3 -no-cache

# Install Node
- name: Install Node
uses: actions/setup-node@v2
uses: actions/setup-node@v3
with:
node-version: "14"
node-version: ${{ env.NODE_VERSION }}
- run: |
echo "${GITHUB_WORKSPACE}/node_modules/.bin" >> $GITHUB_PATH
npm ci
# Install Salesforce CLI
- name: Install Salesforce CLI
run: |
npm install sfdx-cli
npm install -g @salesforce/cli
echo "${GITHUB_WORKSPACE}/node_modules/.bin" >> $GITHUB_PATH
sfdx --version
sf --version
# Install SFDX Scanner
- name: Install SFDX Scanner
run: sf plugins install @salesforce/sfdx-scanner

# sf code scanner
- name: run sf scanner
run: sf scanner:run --target force-app -f table -s 2 --normalize-severity

# Authorise devhub
- name: Autenticate DevHub
run: |
echo "${{ secrets.SERVER_KEY }}" > "server.key"
sfdx force:auth:jwt:grant -i ${{ secrets.CONSUMER_KEY }} -f server.key -u ${{ secrets.USERNAME }} -d -a hub-org
sf org login jwt -i ${{ secrets.CONSUMER_KEY }} -f server.key -o ${{ secrets.USERNAME }} -d -a hub-org
# Build Scratch Org
- name: Run org_builder
uses: actions/setup-python@v3
with:
python-version: "3.10"
cache: 'pip'
cache: "pip"
- run: pip install -r requirements.txt
- run: python org_builder.py -a sfdx-example -d 1 -v hub-org --debug
- run: python org_builder.py -a ${{ env.ORG_ALIAS }} -d 1 -e ${{ env.ADMIN_EMAIL }} -v hub-org --debug

# Run tests
- name: Run Tests
run: sfdx apex:run:test -r human -w 5 -l RunLocalTests -c -v
run: sf apex run test -r human -w 5 -l RunLocalTests -c -v
39 changes: 0 additions & 39 deletions .github/workflows/python-app.yml

This file was deleted.

36 changes: 29 additions & 7 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,30 @@
{
"recommendations": [
"salesforce.salesforcedx-vscode",
"redhat.vscode-xml",
"dbaeumer.vscode-eslint",
"esbenp.prettier-vscode"
]
}
"recommendations": [
"salesforce.salesforcedx-vscode",
"redhat.vscode-xml",
"dbaeumer.vscode-eslint",
"esbenp.prettier-vscode",
"salesforce.salesforcedx-vscode-apex",
"salesforce.salesforcedx-vscode-apex-debugger",
"financialforce.lana",
"chuckjonas.apex-pmd",
"salesforce.salesforcedx-vscode-apex-replay-debugger",
"salesforce.salesforcedx-vscode-lightning",
"aaron-bond.better-comments",
"usernamehw.errorlens",
"visualstudioexptteam.vscodeintellicode",
"visualstudioexptteam.intellicode-api-usage-examples",
"ms-python.isort",
"salesforce.salesforcedx-vscode-lwc",
"ms-python.vscode-pylance",
"njqdev.vscode-python-typehint",
"mechatroner.rainbow-csv",
"salesforce.salesforcedx-vscode-core",
"hugoom.sfdx-autoheader",
"salesforce.salesforce-vscode-slds",
"salesforce.salesforcedx-vscode-soql",
"salesforce.salesforcedx-vscode-visualforce",
"ms-python.black-formatter",
"ms-python.flake8"
]
}
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"prettier.useTabs": true,
"prettier.tabWidth": 4,
"editor.detectIndentation": false,
"editor.insertSpaces": false,
"editor.insertSpaces": true,
"apexPMD.runOnFileOpen": true,
"apexPMD.priorityErrorThreshold": 2,
"apexPMD.priorityWarnThreshold": 4
Expand Down
35 changes: 28 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,37 @@
# Salesforce DX Project: Next Steps
# Exmaple Salesforce DX Project using GitHub Actions.

Now that you’ve created a Salesforce DX project, what’s next? Here are some documentation resources to get you started.
Example Salesfoce CI using GitHub actions.

## How Do You Plan to Deploy Your Changes?
* Static code scan
* Build scratch org
* Run unit tests

Do you want to deploy a set of changes, or create a self-contained application? Choose a [development model](https://developer.salesforce.com/tools/vscode/en/user-guide/development-models).
## Intentionally failing workflow

## Configure Your Salesforce DX Project
The lighting app in this repo has been specififcally written to highlight the workflow's behaviour. Not implementing Salesforce best practices ultimatly leads to a failed unit test.

The `sfdx-project.json` file contains useful configuration information for your project. See [Salesforce DX Project Configuration](https://developer.salesforce.com/docs/atlas.en-us.sfdx_dev.meta/sfdx_dev/sfdx_dev_ws_config.htm) in the _Salesforce DX Developer Guide_ for details about this file.
```
=== Apex Code Coverage for Test Run 7073G00000sJ2H1
TEST NAME CLASS BEING TESTED OUTCOME PERCENT MESSAGE RUNTIME (MS)
─────────────────────────────────── ────────────────── ─────── ─────── ──────────────────────────────────────────────────────────── ────────────
AncestryHelperTest.testGetAncestors AncestryHelper Fail 89% System.LimitException: Too many SOQL queries: 101
Class.AncestryHelper.getAncestors: line 22, column 1
Class.AncestryHelperTest.testGetAncestors: line 23, column 1 594
```

## Read All About It
Looking at the action log we can see that the potential for this failure is highlighted by the static code scanner.
```
LOCATION DESCRIPTION CATEGORY U R L
───────────────────────────────────────────────────── ───────────────────────────────────────────────────── ───────────── ──────────────────────────────────────────────────────────────────────────────────────────
force-app/main/default/classes/AncestryHelper.cls:12 Missing ApexDoc comment Documentation https://pmd.github.io/pmd-6.55.0/pmd_rules_apex_documentation.html#apexdoc
force-app/main/default/classes/AncestryHelper.cls:14 Validate CRUD permission before SOQL/DML operation Security https://pmd.github.io/pmd-6.55.0/pmd_rules_apex_security.html#apexcrudviolation
or enforce user mode
force-app/main/default/classes/AncestryHelper.cls:22 Avoid Soql queries inside loops Performance https://pmd.github.io/pmd-6.55.0/pmd_rules_apex_performance.html#avoidsoqlinloops
```

The _"Avoid Soql queries inside loops"_ message references the same line as the failed unit test. (force-app/main/default/classes/AncestryHelper.cls:22)

## Salesforce CLI documentation

- [Salesforce Extensions Documentation](https://developer.salesforce.com/tools/vscode/)
- [Salesforce CLI Setup Guide](https://developer.salesforce.com/docs/atlas.en-us.sfdx_setup.meta/sfdx_setup/sfdx_setup_intro.htm)
Expand Down
8 changes: 7 additions & 1 deletion org_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,17 @@
SCRATCH_DEF: config/project-scratch-def.json

# Default duration in days
DURATION: 5
DURATION: 10

# Default Devhub
DEVHUB: hub-org

# use_namepspace
USE_NAMESPACE: False

# Preview Release
PREVIEW: False

# List of managed package Ids to install into the Org.
PACKAGE_IDS: []

Expand Down
Loading

0 comments on commit 804ce25

Please sign in to comment.