Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[INTER-167] Semantic release #142

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module.exports = {
},
ecmaVersion: 2020,
sourceType: 'module',
},
},
plugins: ['@typescript-eslint', 'prettier'],
ignorePatterns: ['build/*'],
rules: {
Expand All @@ -27,4 +27,4 @@ module.exports = {
'@typescript-eslint/no-unused-vars': ['error'],
curly: [2, 'all'],
},
}
}
11 changes: 11 additions & 0 deletions .github/workflows/analyze-commits.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: Analyze Commit Messages
on:
pull_request:

permissions:
pull-requests: write
contents: write
jobs:
analyze-commits:
name: Generate docs and coverage report
uses: fingerprintjs/dx-team-toolkit/.github/workflows/analyze-commits.yml@v1
131 changes: 10 additions & 121 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,124 +1,13 @@
name: Release

name: release
on:
workflow_dispatch:
inputs:
version_bump:
description: 'A type of version bump'
default: 'patch'
required: true
type: choice
options:
- major
- minor
- patch
push:
branches:
- main
- test

jobs:
release:
name: Release CloudFront integration distribution
runs-on: ubuntu-20.04

permissions:
contents: write
pull-requests: write

if: github.ref == 'refs/heads/develop'

steps:
- name: Checkout develop branch
uses: actions/checkout@v3
with:
ref: develop
fetch-depth: 0

- name: Install node.js
uses: actions/setup-node@v3
with:
node-version-file: '.node-version'

- name: Set git settings
uses: fregante/setup-git-user@77c1b5542f14ab6db4b8462d6857e31deb988b09

## Build Lambda@Edge function
- name: Install dependencies
run: yarn install

- name: Lint
run: yarn lint

- name: Run tests
run: yarn test

- name: Disable version tags
run: yarn config set version-git-tag false

- name: Bump version
run: yarn version --${{ github.event.inputs.version_bump }}

- name: Build lambda function
run: yarn build

- name: Run type check
run: yarn test:dts

- name: Get new version of lambda@edge
id: version_edge
uses: notiz-dev/github-action-json-property@a5a9c668b16513c737c3e1f8956772c99c73f6e8
with:
path: 'package.json'
prop_path: 'version'

## Build Mgmt-lambda function
- name: Install dependencies
working-directory: ./mgmt-lambda
run: yarn install

- name: Lint
working-directory: ./mgmt-lambda
run: yarn lint

- name: Bump version
working-directory: ./mgmt-lambda
run: yarn version --${{ github.event.inputs.version_bump }}

- name: Build lambda function
working-directory: ./mgmt-lambda
run: yarn build

- name: Get new version of mgmt-lambda
id: version_mgmt
uses: notiz-dev/github-action-json-property@a5a9c668b16513c737c3e1f8956772c99c73f6e8
with:
path: 'mgmt-lambda/package.json'
prop_path: 'version'

- name: Commit and push new version of lambda
run: |
git commit package.json dist/ -m "build: new lambda@edge function v${{steps.version_edge.outputs.prop}}"
git commit mgmt-lambda/package.json mgmt-lambda/dist/ -m "build: new mgmt-lambda function v${{steps.version_mgmt.outputs.prop}}"
git push "https://${GITHUB_ACTOR}:${{ secrets.GITHUB_TOKEN }}@github.com/${GITHUB_REPOSITORY}.git"
git tag -a "v${{steps.version_edge.outputs.prop}}" -m "v${{steps.version_edge.outputs.prop}}"
git push --tags "https://${GITHUB_ACTOR}:${{ secrets.GITHUB_TOKEN }}@github.com/${GITHUB_REPOSITORY}.git"

## Prepare a release

- name: Create a Github release
uses: ncipollo/release-action@a2e71bdd4e7dab70ca26a852f29600c98b33153e
with:
tag: v${{steps.version_edge.outputs.prop}}
name: Release ${{steps.version_edge.outputs.prop}}
generateReleaseNotes: true

- name: Create Pull Request from develop to main
id: create_pr
uses: devops-infra/action-pull-request@e66e2ba93519dc63b9884a26e620e2fd0cffab2c
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
source_branch: develop
target_branch: main
title: New version of scripts v${{ steps.version_edge.outputs.prop }}
body: New version of scripts v${{ steps.version_edge.outputs.prop }}

- name: Check PR outputs
if: ${{ steps.create_pr.outputs.url }}
run: echo "Pull Request URL - ${{ steps.create_pr.outputs.url }}"
build-and-release:
name: 'Build project, run CI checks and publish new release'
uses: fingerprintjs/dx-team-toolkit/.github/workflows/release-typescript-project.yml@v1
secrets:
GH_RELEASE_TOKEN: ${{ secrets.GH_RELEASE_TOKEN }}
4 changes: 4 additions & 0 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npx commitlint --edit $1
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npx lint-staged
15 changes: 15 additions & 0 deletions .husky/pre-push
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash
. "$(dirname "$0")/_/husky.sh"

containsref() { if [[ $2 =~ $1 ]]; then echo 1; else echo 0; fi }

push_command=$(ps -ocommand= -p $PPID | cut -d' ' -f 4)
protected_branch='main'
current_branch=$(git symbolic-ref HEAD | sed -e 's,.*/\(.*\),\1,')
is_push_to_main_origin=$(containsref '[email protected]:/?fingerprintjs/' "$push_command")

# Block pushes only to protected branch in main repository
if [ $is_push_to_main_origin = 1 ] && [ "$protected_branch" = "$current_branch" ]; then
echo "You are on the $protected_branch branch, push blocked."
exit 1 # push will not execute
fi
136 changes: 136 additions & 0 deletions .releaserc
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
{
"branches": [
"main",
{
"name": "test",
"prerelease": true
}
],
"plugins": [
[
"@semantic-release/commit-analyzer",
{
"releaseRules": [
{
"type": "build",
"scope": "deps",
"release": "patch"
},
{
"type": "docs",
"scope": "README",
"release": "patch"
}
]
}
],
[
"@semantic-release/release-notes-generator",
{
"preset": "conventionalCommits",
"presetConfig": {
"types": [
{
"type": "feat",
"section": "Features"
},
{
"type": "feature",
"section": "Features"
},
{
"type": "fix",
"section": "Bug Fixes"
},
{
"type": "perf",
"section": "Performance Improvements"
},
{
"type": "revert",
"section": "Reverts"
},
{
"type": "docs",
"scope": "README",
"section": "Documentation"
},
{
"type": "build",
"scope": "deps",
"section": "Build System"
},
{
"type": "docs",
"section": "Documentation",
"hidden": true
},
{
"type": "style",
"section": "Styles",
"hidden": true
},
{
"type": "chore",
"section": "Miscellaneous Chores",
"hidden": true
},
{
"type": "refactor",
"section": "Code Refactoring",
"hidden": true
},
{
"type": "test",
"section": "Tests",
"hidden": true
},
{
"type": "build",
"section": "Build System",
"hidden": true
},
{
"type": "ci",
"section": "Continuous Integration",
"hidden": true
}
]
}
}
],
"@semantic-release/changelog",
[
"@semantic-release/npm",
{
"npmPublish": false
}
],
[
"@semantic-release/exec",
{
"prepareCmd": "yarn build",
"publishCmd": "./scripts/preparePackage.sh"
}
],
[
"@semantic-release/git",
{
"assets": [
"CHANGELOG.md",
"package.json"
]
}
],
[
"@semantic-release/github",
{
"assets": [
{
"path": "package.zip"
}
]
}
]
]
}
6 changes: 3 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ For proposing changes, use the standard [pull request approach](https://docs.git
aws lambda update-function-code --function-name <LAMBDA_FUNCTION_NAME> --region <AWS_REGION> --zip-file file://lambda.zip --publish
```

You can invoke the function from your local environment using the [Invoke command](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/lambda/invoke.html) in the AWS CLI, for example `aws lambda invoke --function-name <LAMBDA_FUNCTION_NAME> --region <AWS_REGION> --invocation-type RequestResponse --payload <EVENT_JSON>`, where the `<EVENT_JSON>` is the JSON you want to provide to your Lambda function as input. See [examples of events here](test/lambda).
You can invoke the function from your local environment using the [Invoke command](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/lambda/invoke.html) in the AWS CLI, for example `aws lambda invoke --function-name <LAMBDA_FUNCTION_NAME> --region <AWS_REGION> --invocation-type RequestResponse --payload <EVENT_JSON>`, where the `<EVENT_JSON>` is the JSON you want to provide to your Lambda function as input. See [examples of events here](proxy/test/lambda).

To deploy your function to your CloudFront distribution follow the [Cloudfront Developer Guide](https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/lambda-edge-how-it-works-tutorial.html#lambda-edge-how-it-works-tutorial-add-trigger).

Expand All @@ -54,8 +54,8 @@ These tests are run automatically by the `deploy_test_branch.yml` workflow on ev

### How to release a new version

The workflow `release.yml` is responsible for releasing a new version. It has to be run on `develop` branch, and at the end it will create a release and a PR to `main` branch.
The integration is automatically released on every push to the main branch if there are relevant changes. The workflow must be approved by one of the maintainers, first.

ilfa marked this conversation as resolved.
Show resolved Hide resolved
### How to keep your worker up-to-date

CloudFront Integration by Fingerprint always uses the latest stable version for the customers and upgrades customer Lambda@Edge automatically by running CodePipeline once a new version of Lambda@Edge function is available on the public [S3 bucket](s3://fingerprint-pro-cloudfront-integration-lambda-function/release/lambda_latest.zip). The serverless application that contains the CodePipeline is responsible for delivering new updates from the S3 bucket to the customer's infrastructure.
CloudFront Integration by Fingerprint always uses the latest stable version for the customers and upgrades customer Lambda@Edge automatically by running CodePipeline once a new version of Lambda@Edge function is available on the public [S3 bucket](s3://fingerprint-pro-cloudfront-integration-lambda-function/release/lambda_latest.zip). The serverless application that contains the CodePipeline is responsible for delivering new updates from the S3 bucket to the customer's infrastructure.
43 changes: 43 additions & 0 deletions buildspec.release-lambda.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
version: 0.2

phases:
build:
commands:
- node scripts/downloadGithubRelease.mjs
- unzip package.zip -d dist
- cd dist

- zip -r latest.zip fingerprintjs-pro-cloudfront-lambda-function.js
- zip -r latest_mgmt.zip fingerprintjs-pro-cloudfront-mgmt-lambda-function.js

- aws s3api get-object --bucket fingerprint-pro-cloudfront-integration-lambda-function --key release/lambda_latest.zip previous.zip
- aws s3api get-object --bucket fingerprint-pro-cloudfront-integration-lambda-function --key release/mgmt_lambda_latest.zip previous_mgmt.zip

- unzip previous.zip -d previous
- unzip previous_mgmt.zip -d previous_mgmt

- diff previous/fingerprintjs-pro-cloudfront-lambda-function.js fingerprintjs-pro-cloudfront-lambda-function.js; diffStatus=$?
- diff previous_mgmt/fingerprintjs-pro-cloudfront-mgmt-lambda-function.js fingerprintjs-pro-cloudfront-mgmt-lambda-function.js; mgmtDiffStatus=$?

- echo $diffStatus
- echo $mgmtDiffStatus

- >-
if [ $diffStatus -eq 0 ]; then
echo "Files are the same. Don't need to upload the file."
elif [ $diffStatus -eq 1 ]; then
echo "Files are different. Uploading new version."
aws s3api put-object --body latest.zip --bucket fingerprint-pro-cloudfront-integration-lambda-function --key release/lambda_latest_test.zip
else
echo "There was something wrong with the diff command."
fi

- >-
if [ $mgmtDiffStatus -eq 0 ]; then
echo "Files are the same. Don't need to upload the file."
elif [ $mgmtDiffStatus -eq 1 ]; then
echo "Files are different. Uploading new version."
aws s3api put-object --body latest_mgmt.zip --bucket fingerprint-pro-cloudfront-integration-lambda-function --key release/mgmt_lambda_latest_test.zip
else
echo "There was something wrong with the diff command."
fi
1 change: 1 addition & 0 deletions commitlint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = { extends: ['@commitlint/config-conventional'] }
Loading
Loading