Skip to content

Commit

Permalink
feat: Add bundling and github action CI CD to publish package (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
long-wan-ep authored Jun 10, 2022
1 parent db496ea commit d5085d9
Show file tree
Hide file tree
Showing 11 changed files with 5,538 additions and 4,076 deletions.
10 changes: 10 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"presets": [
[
"@babel/preset-env",
{
"useBuiltIns": "entry"
}
]
]
}
86 changes: 86 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
name: CI/CD

on:
push:
pull_request:
branches:
- 'main'

jobs:
# This job uses skip-duplicate-actions to skip one of the duplicate workflow runs when you push to a branch with an open PR.
check_duplicate_workflow:
needs: []
runs-on: ubuntu-20.04
outputs:
should_skip: ${{ steps.skip_check.outputs.should_skip }}
steps:
- id: skip_check
uses: fkirc/[email protected]
with:
skip_after_successful_duplicate: 'true'
concurrent_skipping: 'same_content_newer'
do_not_skip: '["push"]'

lint:
needs: [check_duplicate_workflow]
runs-on: ubuntu-20.04
if: ${{ needs.check_duplicate_workflow.outputs.should_skip != 'true' }}
steps:
- name: Check out repository code
uses: actions/checkout@v3
- name: Run lint
run: ./gradlew lint

build:
needs: [check_duplicate_workflow]
runs-on: ubuntu-20.04
if: ${{ needs.check_duplicate_workflow.outputs.should_skip != 'true' }}
steps:
- name: Check out repository code
uses: actions/checkout@v3
- name: Build bundles
run: ./gradlew build
- name: Upload build artifacts
uses: actions/upload-artifact@v3
with:
name: ${{ github.event.repository.name }}-${{ github.sha }}-${{ github.run_id }}-bundles
path: build
retention-days: 3

test:
needs: [check_duplicate_workflow]
runs-on: ubuntu-20.04
if: ${{ needs.check_duplicate_workflow.outputs.should_skip != 'true' }}
steps:
- name: Check out repository code
uses: actions/checkout@v3
- name: Run tests
run: ./gradlew unit_test
- name: Upload test results
uses: actions/upload-artifact@v2
with:
name: ${{ github.event.repository.name }}-${{ github.sha }}-${{ github.run_id }}-${{ github.job }}-results
path: build/test-report
retention-days: 3
- name: Publish test results
uses: EnricoMi/[email protected]
with:
files: build/test-report/**/*.xml

release:
needs: [lint, build, test]
runs-on: ubuntu-20.04
if: ${{ github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/beta') }}
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN_ELASTICPATH }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: Check out repository code
uses: actions/checkout@v2
- name: Download build artifacts
uses: actions/download-artifact@v3
with:
name: ${{ github.event.repository.name }}-${{ github.sha }}-${{ github.run_id }}-bundles
path: build
- name: Release, publish package
run: ./gradlew release
31 changes: 7 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,22 @@ Add `remarkable-oembed` to your project using a package manager. For example:
Using `yarn`:

```sh
yarn add https://github.com/elasticpath/remarkable-oembed#v1.0.0 --dev
yarn add @elasticpath/remarkable-oembed --dev
```

Using `npm`:

```sh
npm install https://github.com/elasticpath/remarkable-oembed#v1.0.0 --save-dev
npm install @elasticpath/remarkable-oembed --save-dev
```

**Note**: The above examples show adding the package using the source repo's URL. The version number at the end is a git tag. Ideally it should be installed from npm registry but this plugin is not published to npm registry yet.

## Usage

Enable the `remarkable-oembed` plugin and let Remarkable parse the markdown content:

``` js
const { Remarkable } = require('remarkable')
const remarkableOembed = require('remarkable-oembed')
const remarkableOembed = require('@elasticpath/remarkable-oembed')

let md = new Remarkable().use(remarkableOembed)
md.render('!oembed[](https://www.youtube.com/watch?v=7ALwNmwYxBg)')
Expand Down Expand Up @@ -117,29 +115,14 @@ Below are some useful commands that can be executed from the root of this reposi

- `./gradlew clean`: Removes `build` directory so that you have a fresh build result.

- `./gradlew rollup`: Bundles the `.js` files for NPM release.

- `./gradlew unit_test`: Runs the mocha unit tests for the source files in `src` directory. Generates reports in `build/test-report` and `build/coverage-report` directories as well as your terminal.

- `./gradlew lint`: Runs the eslint for all `.js` files. Generates reports in `build/lint-report` directory as well as your terminal.

- `./gradlew test`: Runs all test related gradle tasks, including `unit_test` and `lint`.

### Commit convention

## Maintenance

This plugin currently is not published it to an npm registry. This section of the document is for maintainers of this repo on process for maintaining changes and release process.

### Release

[Semantic Versioning](https://semver.org/) must be followed. When a new release is required, create a Git Tag and a release in GitHub following semantic versioning schema.

- In GitHub repo, click "Create a new release"
- In the "New Release" page:
- From the "Choose a tag" dropdown, type a new release version; for example: `v1.0.0`.
- Type the same version number as "Release Title"
- Give a brief description in the text box. Ideally a list of PRs with features/fixes added and the corresponding contributor's name.
- Click "Publish Release".

The above steps will create a new git tag as well as create a new GitHub release.

Ideally we'd have the above steps automated and is taken care of through GitHub Actions as part of CI CD process.

Publishing to NPM and releasing in GitHub is automated by the CI/CD pipeline in this repo, and uses [Semantic Release](https://github.com/semantic-release/semantic-release), commit messages must follow the format described in the documentation for a release to be triggered.
21 changes: 20 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ node {

// Version of node to download and install (only used if download is true)
// It will be unpacked in the workDir
version = '14.16.0'
version = '16.15.0'

// Version of Yarn to use
// Any Yarn task first installs Yarn in the yarnWorkDir
Expand All @@ -29,10 +29,21 @@ yarn_install {


// -------- Build related tasks ----------
task rollup(type: YarnTask) {
description 'Bundle all .js files'
group 'Build'

dependsOn 'yarn_install'

args = ['rollup']
}

clean {
delete 'node_modules', '.nyc_output'
}

build.dependsOn 'rollup'


// -------- Test related tasks ----------
task lint(type: YarnTask) {
Expand Down Expand Up @@ -66,3 +77,11 @@ task test {

dependsOn 'lint', 'unit_test'
}

// -------- Release related tasks ----------
task release(type: NpxTask) {
description 'Release to NPM and GitHub'
group 'Release'

command = 'semantic-release'
}
Loading

0 comments on commit d5085d9

Please sign in to comment.