Skip to content

Commit

Permalink
Merge pull request #30 from maaaaarco/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
maaaaarco authored Oct 17, 2020
2 parents 313f385 + 41f54f6 commit e441f7b
Show file tree
Hide file tree
Showing 23 changed files with 705 additions and 36 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
name: PR Validate
name: Pull Request to Develop

on:
pull_request:
branches: [ develop ]

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

steps:
Expand All @@ -19,6 +18,10 @@ jobs:
tar xJf sfdx-linux-amd64.tar.xz -C sfdx-cli --strip-components 1
./sfdx-cli/install
- name: Install jq
run: |
sudo apt-get install jq
- name: Populate auth file
shell: bash
run: 'echo ${{secrets.DEVHUB_SFDX_URL}} > ./DEVHUB_SFDX_URL.txt'
Expand All @@ -32,6 +35,12 @@ jobs:
- name: Push source to scratch org
run: 'sfdx force:source:push'

- name: Check code coverage
run: |
sfdx force:apex:test:run --codecoverage --resultformat json --synchronous --testlevel RunLocalTests --wait 10 > tests.json
coverage=$(jq .result.summary.orgWideCoverage tests.json | grep -Eo "[[:digit:]]+")
test $coverage -ge 75
- name: Delete scratch org
if: always()
run: 'sfdx force:org:delete -p -u ci_scratch'
15 changes: 10 additions & 5 deletions .github/workflows/push-develop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,22 @@ jobs:
run: 'sfdx force:auth:sfdxurl:store -f ./DEVHUB_SFDX_URL.txt -a devhub -d'

- name: Create new version
run: 'sfdx force:package:version:create -x -p "Spaghetti CMD" -w 60'
run: |
sfdx force:package:version:create -x -p "Spaghetti CMD" -w 60 --codecoverage
new_version_id=$(grep -o "04t[[:alnum:]]\{15\}" sfdx-project.json | tail -n1)
echo "::set-env name=version_id::${new_version_id}"
- name: Check code coverage
run: |
test $(sfdx force:package:version:report -p "$version_id" --json | jq .result.HasPassedCodeCoverageCheck) = 'true'
- name: Install new version in Dev Hub
run: |
new_version_id=$(grep -o "04t[[:alnum:]]\{15\}" sfdx-project.json | tail -n1)
sfdx force:package:install -p "$new_version_id" -u devhub --wait 10 --publishwait 10
sfdx force:package:install -p "$version_id" -u devhub --wait 10 --publishwait 10
- name: Store new version id
run: |
new_version_id=$(grep -o "04t[[:alnum:]]\{15\}" sfdx-project.json | tail -n1)
sed -i -e "s/04t[[:alnum:]]\{15\}/${new_version_id}/" README.md
sed -i -e "s/04t[[:alnum:]]\{15\}/${version_id}/" README.md
git config user.name "release[bot]"
git config user.email "<>"
git add README.md
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/push-master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
- name: Promote latest version
run: |
version_id=$(grep -o "04t[[:alnum:]]\{15\}" sfdx-project.json | tail -n1)
sfdx force:package:version:promote -p "$version_id"
sfdx force:package:version:promote -p "$version_id" --noprompt
- name: Tag new release
run: |
Expand Down
23 changes: 23 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
## Contributing

1. Familiarize yourself with the codebase
1. Create a new issue before starting your project so that we can keep track of
what you are trying to add/fix.
1. Fork this repository.
1. Edit the code in your fork.
1. Send us a pull request when you are done. We'll review your code, suggest any
needed changes, and merge it in.

## Branches

- We work in `develop`.
- Every push on `develop` will create a new package version
- We release from `master`.
- Our work happens in _topic_ branches (feature and/or bug-fix).
- feature as well as bug-fix branches are based on `develop`


### Merging `develop` into `master`

- When a development cycle finishes, the content of the `develop` is merged into `master` branch.
- The latest package version is then promoted to `released`
14 changes: 9 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
![release](https://img.shields.io/badge/release-Summer_'20-g)
![release](https://img.shields.io/badge/release-Winter_'21-g)

# Custom Metadata Loader
Create or Update Custom Metadata Type records from CSV file
Expand All @@ -12,6 +12,7 @@ Create or Update Custom Metadata Type records from CSV file
- [CSV columns](#user-guide-csv-cols)
- [Limitations](#user-guide-limitations)
- [Demo](#demo)
- [Contributing](#contributing)
- [Credits](#credits)

# Installation options <a id="installation"></a>
Expand All @@ -21,15 +22,15 @@ Create or Update Custom Metadata Type records from CSV file
</a>

## URL (recommended) <a id="installation-url"></a>
- [Production/Developer](https://login.salesforce.com/packaging/installPackage.apexp?p0=04t1t000002hza1AAA)
- [Sandbox](https://test.salesforce.com/packaging/installPackage.apexp?p0=04t1t000002hza1AAA)
- [Production/Developer](https://login.salesforce.com/packaging/installPackage.apexp?p0=04t1t000003HUFbAAO)
- [Sandbox](https://test.salesforce.com/packaging/installPackage.apexp?p0=04t1t000003HUFbAAO)

This approach is recommended since all components will be deployed using a namespace, removing the chance of failures due to conflicting API names.

## Unlocked package (recommended) <a id="installation-unlocked-pkg"></a>
You can install this as an Unlocked Package, using the CLI, by running the following command:
```bash
sfdx force:package:install --package "04t1t000002hza1AAA" --targetusername YOUR_ORG_ALIAS --wait 10 --publishwait 10
sfdx force:package:install --package "04t1t000003HUFbAAO" --targetusername YOUR_ORG_ALIAS --wait 10 --publishwait 10
```
This approach is recommended since all components will be deployed using a namespace, removing the chance of failures due to conflicting API names.

Expand Down Expand Up @@ -72,12 +73,15 @@ This application does not impose any hard limit on the CSV file size or number o

If your CSV file contains more than 250 rows the application will automatically split it into smaller chunks of 250 rows each. Chunks will be loaded sequentially.

In June 11, 2020 the [Salesforce CLI](https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_reference.meta/sfdx_cli_reference/cli_reference.htm) released a bunch of new commands to work with Custom Metadata Types. Among these there's one that allows records creation from a CSV file. Check them out [here](https://github.com/forcedotcom/cli/blob/master/releasenotes/v48.md#48181-june-11-2020).
For more complex use cases consider that the [Salesforce CLI](https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_reference.meta/sfdx_cli_reference/cli_reference.htm) has a bunch of commands to work with Custom Metadata Types. Check them out [here](https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_reference.meta/sfdx_cli_reference/cli_reference_force_cmdt.htm#cli_reference_force_cmdt).

# Demo <a id="demo"></a>
YouTube video:

[![Demo Video](https://img.youtube.com/vi/abYr7B-5vsA/0.jpg)](https://www.youtube.com/watch?v=abYr7B-5vsA)

# Contribute <a id="contributing"></a>
If you are interested in contributing, please take a look at the [CONTRIBUTING](CONTRIBUTING.md) guide.

# Credits <a id="credits"></a>
- [Papa Parse](https://www.papaparse.com/) for its amazing Javascript CSV parser
37 changes: 37 additions & 0 deletions cmd-loader/main/default/classes/CMDConnectApiDelegate.cls
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright (c) 2020 Marco Zeuli
* Licensed under MIT license.
* For full license text, see LICENSE file in the repo root or https://opensource.org/licenses/MIT
* If you would like to contribute https://github.com/maaaaarco/spaghetti-cmd-loader
*/

/**
* ConnectApi methods are not supported in data siloed tests.
* This Delegate allows for testing without using the SeeAllData=true
*/
public inherited sharing class CMDConnectApiDelegate {
/**
* Creates new FeedItem
* @return Created FeedItem
*/
public ConnectApi.FeedElement postFeedElement(
Id networkId,
ConnectApi.FeedItemInput feed
) {
return ConnectApi.ChatterFeeds.postFeedElement(networkId, feed);
}

/**
* Retrieves FeedItem records created in the current day
* @param parentId Parent Id of FeedItem records
* @return A list of FeedItem or an empty list
*/
public List<FeedItem> getTodayFeedItems(Id parentId){
return [
SELECT Body
FROM FeedItem
WHERE ParentId = :UserInfo.getUserId() AND CreatedDate = TODAY
LIMIT 1000
];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>50.0</apiVersion>
<status>Active</status>
</ApexClass>
8 changes: 8 additions & 0 deletions cmd-loader/main/default/classes/CMDConnectApiDelegateTest.cls
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
@IsTest
private class CMDConnectApiDelegateTest {
@IsTest
static void getTodayFeedItemsReturnsCorrectly() {
List<FeedItem> res = new CMDConnectApiDelegate().getTodayFeedItems(UserInfo.getUserId());
System.assertNotEquals(null, res);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>50.0</apiVersion>
<status>Active</status>
</ApexClass>
2 changes: 1 addition & 1 deletion cmd-loader/main/default/classes/CMDConstants.cls-meta.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>48.0</apiVersion>
<apiVersion>50.0</apiVersion>
<status>Active</status>
</ApexClass>
13 changes: 9 additions & 4 deletions cmd-loader/main/default/classes/CMDDeployCallback.cls
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,18 @@
*/
@NamespaceAccessible
public inherited sharing class CMDDeployCallback implements Metadata.DeployCallback {
@TestVisible
static final Integer MAX_FAILURES = 20;

Metadata.DeployResult result;

@TestVisible
private CMDConnectApiDelegate feedApi;

public CMDDeployCallback() {
this.feedApi = new CMDConnectApiDelegate();
}

public void handleResult(
Metadata.DeployResult result,
Metadata.DeployCallbackContext context
Expand Down Expand Up @@ -42,10 +50,7 @@ public inherited sharing class CMDDeployCallback implements Metadata.DeployCallb
feedItemInput.feedElementType = ConnectApi.FeedElementType.FeedItem;
feedItemInput.subjectId = result.createdBy;

ConnectApi.FeedElement feedElement = ConnectApi.ChatterFeeds.postFeedElement(
Network.getNetworkId(),
feedItemInput
);
feedApi.postFeedElement(Network.getNetworkId(), feedItemInput);
}

private String parseDeploymentStatus() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>48.0</apiVersion>
<apiVersion>50.0</apiVersion>
<status>Active</status>
</ApexClass>
Loading

0 comments on commit e441f7b

Please sign in to comment.