Skip to content

Commit

Permalink
Add GitHub release workflow and fix ci workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
diogotorres97 authored and satazor committed Dec 20, 2023
1 parent 53dbcd7 commit 58a6054
Show file tree
Hide file tree
Showing 9 changed files with 2,330 additions and 68 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
!.release-it.js
28 changes: 20 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,27 @@ name: Node CI
on: [push]

jobs:
build:

unit:
runs-on: ubuntu-latest
strategy:
matrix:
node: [18, 20]
name: Node v${{ matrix.node }}

steps:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
with:
node-version: 14
- run: yarn
- run: yarn test
- name: Checkout code
uses: actions/checkout@v4

- name: Setup Node.js version
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}

- name: Install dependencies
run: yarn

- name: Run lint
run: yarn lint

- name: Run tests
run: yarn test
47 changes: 47 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Release

on:
workflow_dispatch:
inputs:
VERSION_BUMP:
description: 'The version bump'
type: choice
options:
- major
- minor
- patch
default: minor
required: true

jobs:
release:
runs-on: ubuntu-latest
concurrency: 1
environment: release

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
token: ${{ secrets.RELEASE_GITHUB_TOKEN }}

- name: Setup Node.js version
uses: actions/setup-node@v4
with:
node-version: 20

- name: Enable yarn
run: corepack enable

- name: Install dependencies
run: yarn install --frozen-lockfile

- name: Configure git
run: |
git config user.name "Uphold"
git config user.email "[email protected]"
- name: Generate release
env:
GITHUB_TOKEN: ${{ secrets.RELEASE_GITHUB_TOKEN }}
run: yarn run release --increment "${{ github.event.inputs.VERSION_BUMP }}" -V
22 changes: 22 additions & 0 deletions .release-it.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
module.exports = {
git: {
changelog: 'echo "## Changelog\n\n$(npx @uphold/github-changelog-generator -f unreleased | tail -n +4 -f)"',
commitMessage: 'Release ${version}',
requireBranch: 'master',
requireCommits: true,
tagName: 'v${version}'
},
github: {
release: true,
releaseName: 'v${version}'
},
hooks: {
'after:bump': [
'echo "$(npx @uphold/github-changelog-generator -f v${version})\n$(tail -n +2 CHANGELOG.md)" > CHANGELOG.md',
'git add CHANGELOG.md --all'
]
},
npm: {
publish: true
}
};
15 changes: 2 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,20 +100,9 @@ anonymize(data);
// }
```

## Releasing a new version
## Release process

- Diff the current code with the latest tag and make sure the output is expected.

```sh
git diff $(git describe --tags `git rev-list --tags --max-count=1`)..master
```

- Create a release commit and tag using [semver](http://semver.org) standards, and push them.

```sh
yarn release ["major" | "minor" | "patch" | <custom version number>]
git push origin master --tags
```
The release of a version is automated via the [release](https://github.com/uphold/anonymizer/.github/workflows/release.yml) GitHub workflow. Run it by clicking the "Run workflow" button.

## License

Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@
"test": "test"
},
"scripts": {
"changelog": "uphold-scripts changelog $npm_package_version",
"lint": "uphold-scripts lint",
"release": "uphold-scripts release",
"test": "uphold-scripts test",
"version": "uphold-scripts version"
"lint": "uphold-scripts lint .",
"release": "release-it",
"test": "uphold-scripts test"
},
"dependencies": {
"json-stringify-safe": "^5.0.1",
Expand All @@ -26,6 +24,8 @@
"traverse": "^0.6.6"
},
"devDependencies": {
"@uphold/github-changelog-generator": "^3.4.0",
"release-it": "^17.0.1",
"uphold-scripts": "^0.9.0"
},
"pre-commit": [
Expand Down
6 changes: 3 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
* Module dependencies.
*/

const { serializeError } = require('serialize-error');
const { cloneDeep, cloneDeepWith, get, set } = require('lodash');
const { serializeError } = require('serialize-error');
const stringify = require('json-stringify-safe');
const traverse = require('traverse');

Expand Down Expand Up @@ -129,12 +129,12 @@ module.exports.anonymizer = (
const blacklistedKeys = new Set();
const obj = parseAndSerialize(values, serializers);

traverse(obj).forEach(function() {
traverse(obj).forEach(function () {
const path = this.path.join('.');
const isBuffer = Buffer.isBuffer(get(values, path));

if (trim) {
this.after(function(node) {
this.after(function (node) {
if (!this.isLeaf && Object.values(node).every(value => value === undefined)) {
return this.isRoot ? this.update(undefined, true) : this.delete();
}
Expand Down
21 changes: 17 additions & 4 deletions test/src/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,10 @@ describe('Anonymizer', () => {
return 'biz';
});
const whitelist = ['*'];
const serializers = [{ path: 'foo', serializer: foobar }, { path: 'foz', serializer: fozbar }];
const serializers = [
{ path: 'foo', serializer: foobar },
{ path: 'foz', serializer: fozbar }
];
const anonymize = anonymizer({ whitelist }, { serializers });

const result = anonymize(data);
Expand Down Expand Up @@ -478,7 +481,10 @@ describe('Anonymizer', () => {
const serializer = jest.fn(() => {
throw new Error('foobar');
});
const serializers = [{ path: 'foo', serializer }, { path: 'foz', serializer }];
const serializers = [
{ path: 'foo', serializer },
{ path: 'foz', serializer }
];
const whitelist = ['*'];
const anonymize = anonymizer({ whitelist }, { serializers });

Expand All @@ -495,7 +501,11 @@ describe('Anonymizer', () => {
it('should serialize errors when `serializeError()` is applied', () => {
const error = new Error('foobar');
const serializer = jest.fn(serializeError);
const serializers = [{ path: 'e', serializer }, { path: 'err', serializer }, { path: 'error', serializer }];
const serializers = [
{ path: 'e', serializer },
{ path: 'err', serializer },
{ path: 'error', serializer }
];
const whitelist = ['*'];
const anonymize = anonymizer({ whitelist }, { serializers });

Expand Down Expand Up @@ -530,7 +540,10 @@ describe('Anonymizer', () => {
it('should serialize errors when `datadogSerializer()` is applied', () => {
const error = new Error('foobar');
const serializer = jest.fn(datadogSerializer);
const serializers = [{ path: 'err', serializer }, { path: 'error', serializer }];
const serializers = [
{ path: 'err', serializer },
{ path: 'error', serializer }
];
const whitelist = ['error.foo', 'error.kind', 'error.message', 'error.name', 'error.stack'];
const anonymize = anonymizer({ whitelist }, { serializers });

Expand Down
Loading

0 comments on commit 58a6054

Please sign in to comment.