From 83b6e4e11bb632e06fefabaa9ab05775682f001e Mon Sep 17 00:00:00 2001 From: Taly Date: Fri, 27 Aug 2021 15:53:44 +0300 Subject: [PATCH 1/9] send commits on build --- .../workflows/build-and-push-docker-image.yml | 18 +++++- .github/workflows/bump-version.yml | 61 +++++++++++++++++++ index.ts | 6 +- package.json | 2 +- tsconfig.json | 1 + yarn.lock | 8 +-- 6 files changed, 89 insertions(+), 7 deletions(-) create mode 100644 .github/workflows/bump-version.yml diff --git a/.github/workflows/build-and-push-docker-image.yml b/.github/workflows/build-and-push-docker-image.yml index 14ff73fa..ad3e4a4e 100644 --- a/.github/workflows/build-and-push-docker-image.yml +++ b/.github/workflows/build-and-push-docker-image.yml @@ -1,9 +1,14 @@ name: Build and push docker image -on: [push] +on: + push: + branches: + - prod + - stage env: DOCKER_REPO: ${{ secrets.DOCKER_USERNAME }}/hawk-api + HAWK_TOKEN: ${{ secrets.HAWK_TOKEN }} jobs: build: @@ -12,6 +17,17 @@ jobs: - name: Checkout repository uses: actions/checkout@v2 + # Get package new version name + - name: Get package info + id: packageInfo + uses: codex-team/action-nodejs-package-info@v1 + + - name: Send commits to Hawk + run: | + curl https://raw.githubusercontent.com/codex-team/hawk.release/feature/commits-sending-script/scripts/commits.sh -O + chmod +x ./commits.sh + ./commits.sh -r="${{ steps.package.outputs.version }}" -t=${{ env.HAWK_TOKEN }} + - name: Build and push docker image uses: docker/build-push-action@v1 with: diff --git a/.github/workflows/bump-version.yml b/.github/workflows/bump-version.yml new file mode 100644 index 00000000..ad5b0955 --- /dev/null +++ b/.github/workflows/bump-version.yml @@ -0,0 +1,61 @@ +name: Bump version in PR + +on: [pull_request] + +jobs: + # If pull request was merged then we should check for a package version update + check-version-update: + runs-on: ubuntu-latest + steps: + # Checkout to target branch + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + + # Get package new version name + - name: Get package info + id: packageNew + uses: codex-team/action-nodejs-package-info@v1 + + # Checkout to the base commit before merge + - name: Checkout to the base commit before merge + run: git checkout ${{ github.event.pull_request.base.sha }} + + # Get package old version name + - name: Get package info + id: packageOld + uses: codex-team/action-nodejs-package-info@v1 + + # Stop workflow and do not bump version if it was changed already + - name: Stop workflow and do not bump version if it was changed already + uses: andymckay/cancel-action@0.2 + if: steps.packageOld.outputs.version != steps.packageNew.outputs.version + + bump-version: + needs: check-version-update + runs-on: ubuntu-latest + steps: + # Checkout to target branch + - uses: actions/checkout@v2 + + # Setup node environment + - uses: actions/setup-node@v1 + with: + node-version: 15 + registry-url: https://registry.npmjs.org/ + + # Bump version to the next prerelease (patch) with rc suffix + - name: Suggest the new version + run: yarn version --patch --no-git-tag-version + + # Get package new version name + - name: Get package info + id: package + uses: codex-team/action-nodejs-package-info@v1 + + # Commit version upgrade + - uses: EndBug/add-and-commit@v7 + with: + author_name: github-actions + author_email: 41898282+github-actions[bot]@users.noreply.github.com + message: "Bump version up to ${{ steps.package.outputs.version }}" diff --git a/index.ts b/index.ts index 0ec2eb22..20cc0394 100644 --- a/index.ts +++ b/index.ts @@ -1,10 +1,14 @@ import './src/env'; import HawkAPI from './src'; import HawkCatcher from '@hawk.so/nodejs'; +import { version } from './package.json'; /** Enable HawkCatcher */ if (process.env.HAWK_CATCHER_TOKEN) { - HawkCatcher.init(process.env.HAWK_CATCHER_TOKEN); + HawkCatcher.init({ + token: process.env.HAWK_CATCHER_TOKEN, + release: version, + }); } const app = new HawkAPI(); diff --git a/package.json b/package.json index b6d4bd82..dfe9838c 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,7 @@ "typescript": "^3.7.5" }, "dependencies": { - "@hawk.so/nodejs": "^3.0.10", + "@hawk.so/nodejs": "^3.1.1", "@types/amqp-connection-manager": "^2.0.4", "@types/debug": "^4.1.5", "@types/escape-html": "^1.0.0", diff --git a/tsconfig.json b/tsconfig.json index d306d722..54843532 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -21,6 +21,7 @@ // "importHelpers": true, /* Import emit helpers from 'tslib'. */ // "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */ // "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */ + "resolveJsonModule": true, /* Allows importing modules with a ‘.json’ extension, which is a common practice in node projects. */ /* Strict Type-Checking Options */ "strict": true, /* Enable all strict type-checking options. */ diff --git a/yarn.lock b/yarn.lock index 05391d6f..d18f8ae7 100644 --- a/yarn.lock +++ b/yarn.lock @@ -356,10 +356,10 @@ dependencies: "@f/map-obj" "^1.2.2" -"@hawk.so/nodejs@^3.0.10": - version "3.0.10" - resolved "https://registry.yarnpkg.com/@hawk.so/nodejs/-/nodejs-3.0.10.tgz#11e34f2572f53088913b1d45e3abfaa391386904" - integrity sha512-KpVk34n6ttX21KEJlGmKi7Pg4bh+x3x1Ot8O1Xy4ZRb+ob208PU/ThDEOeJgf/QH3QBTTNnNWK/HvjSW81TkHg== +"@hawk.so/nodejs@^3.1.1": + version "3.1.1" + resolved "https://registry.yarnpkg.com/@hawk.so/nodejs/-/nodejs-3.1.1.tgz#fc68b77833ce14f2491c77c58c724e51366c47dd" + integrity sha512-VzVGYDat+dEmtSFp777Ql9GYqHwliO5aoNbqdK3xAa7tbe3FPrSv4B8SsyJEJJuXkTjAKOlWmX0zjkjlY80A6w== dependencies: "@hawk.so/types" "^0.1.15" axios "^0.21.1" From 749b35581eee82b5b8479b189c2f26c999093bf0 Mon Sep 17 00:00:00 2001 From: Taly Date: Fri, 27 Aug 2021 15:56:39 +0300 Subject: [PATCH 2/9] add name to release id --- .github/workflows/build-and-push-docker-image.yml | 2 +- index.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build-and-push-docker-image.yml b/.github/workflows/build-and-push-docker-image.yml index ad3e4a4e..e0f126f0 100644 --- a/.github/workflows/build-and-push-docker-image.yml +++ b/.github/workflows/build-and-push-docker-image.yml @@ -26,7 +26,7 @@ jobs: run: | curl https://raw.githubusercontent.com/codex-team/hawk.release/feature/commits-sending-script/scripts/commits.sh -O chmod +x ./commits.sh - ./commits.sh -r="${{ steps.package.outputs.version }}" -t=${{ env.HAWK_TOKEN }} + ./commits.sh -r=${{ steps.package.outputs.name }}-${{ steps.package.outputs.version }} -t=${{ env.HAWK_TOKEN }} - name: Build and push docker image uses: docker/build-push-action@v1 diff --git a/index.ts b/index.ts index 20cc0394..aa164117 100644 --- a/index.ts +++ b/index.ts @@ -1,13 +1,13 @@ import './src/env'; import HawkAPI from './src'; import HawkCatcher from '@hawk.so/nodejs'; -import { version } from './package.json'; +import { name, version } from './package.json'; /** Enable HawkCatcher */ if (process.env.HAWK_CATCHER_TOKEN) { HawkCatcher.init({ token: process.env.HAWK_CATCHER_TOKEN, - release: version, + release: `${name}-${version}`, }); } From e75dfff6af246c60338f70ff313d3fde00ffb932 Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Fri, 27 Aug 2021 12:58:03 +0000 Subject: [PATCH 3/9] Bump version up to 1.0.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index dfe9838c..b1f81417 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "hawk.api", - "version": "1.0.0", + "version": "1.0.1", "main": "index.ts", "license": "UNLICENSED", "scripts": { From 2ed4e8a4bcef84dce77798a3ca87e1f9863127d1 Mon Sep 17 00:00:00 2001 From: Taly Date: Fri, 27 Aug 2021 16:05:30 +0300 Subject: [PATCH 4/9] remove commits.sh --- .github/workflows/build-and-push-docker-image.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/build-and-push-docker-image.yml b/.github/workflows/build-and-push-docker-image.yml index e0f126f0..f5fbab4b 100644 --- a/.github/workflows/build-and-push-docker-image.yml +++ b/.github/workflows/build-and-push-docker-image.yml @@ -27,6 +27,7 @@ jobs: curl https://raw.githubusercontent.com/codex-team/hawk.release/feature/commits-sending-script/scripts/commits.sh -O chmod +x ./commits.sh ./commits.sh -r=${{ steps.package.outputs.name }}-${{ steps.package.outputs.version }} -t=${{ env.HAWK_TOKEN }} + rm ./commits.sh - name: Build and push docker image uses: docker/build-push-action@v1 From 1a82638a85b93fe61647c1acab7afe699d8cb39d Mon Sep 17 00:00:00 2001 From: Taly Date: Fri, 3 Sep 2021 13:51:40 +0300 Subject: [PATCH 5/9] update workflow --- .github/workflows/build-and-push-docker-image.yml | 11 +++++------ index.ts | 2 ++ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build-and-push-docker-image.yml b/.github/workflows/build-and-push-docker-image.yml index f5fbab4b..a59b4f66 100644 --- a/.github/workflows/build-and-push-docker-image.yml +++ b/.github/workflows/build-and-push-docker-image.yml @@ -22,12 +22,11 @@ jobs: id: packageInfo uses: codex-team/action-nodejs-package-info@v1 - - name: Send commits to Hawk - run: | - curl https://raw.githubusercontent.com/codex-team/hawk.release/feature/commits-sending-script/scripts/commits.sh -O - chmod +x ./commits.sh - ./commits.sh -r=${{ steps.package.outputs.name }}-${{ steps.package.outputs.version }} -t=${{ env.HAWK_TOKEN }} - rm ./commits.sh + - name: Send release data + uses: codex-team/hawk.releases@v0 + with: + release: ${{ steps.packageInfo.outputs.name }}-${{ steps.packageInfo.outputs.version }} + token: ${{ secrets.HAWK_TOKEN }} - name: Build and push docker image uses: docker/build-push-action@v1 diff --git a/index.ts b/index.ts index aa164117..aa4c8705 100644 --- a/index.ts +++ b/index.ts @@ -9,6 +9,8 @@ if (process.env.HAWK_CATCHER_TOKEN) { token: process.env.HAWK_CATCHER_TOKEN, release: `${name}-${version}`, }); + + HawkCatcher.send(new Error('API is started')); } const app = new HawkAPI(); From 1bad5aee3b560463a23b95c588a4beb32a861fec Mon Sep 17 00:00:00 2001 From: Taly Date: Fri, 3 Sep 2021 14:09:33 +0300 Subject: [PATCH 6/9] Update build-and-push-docker-image.yml --- .github/workflows/build-and-push-docker-image.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-and-push-docker-image.yml b/.github/workflows/build-and-push-docker-image.yml index a59b4f66..7dd2c592 100644 --- a/.github/workflows/build-and-push-docker-image.yml +++ b/.github/workflows/build-and-push-docker-image.yml @@ -23,7 +23,7 @@ jobs: uses: codex-team/action-nodejs-package-info@v1 - name: Send release data - uses: codex-team/hawk.releases@v0 + uses: codex-team/hawk.releases@v1 with: release: ${{ steps.packageInfo.outputs.name }}-${{ steps.packageInfo.outputs.version }} token: ${{ secrets.HAWK_TOKEN }} From 18339da8ac140fc6bcd7943348ebd66001e82e57 Mon Sep 17 00:00:00 2001 From: Taly Date: Fri, 3 Sep 2021 14:19:26 +0300 Subject: [PATCH 7/9] Update package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index b1f81417..cdcc07a9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "hawk.api", - "version": "1.0.1", + "version": "1.0.2", "main": "index.ts", "license": "UNLICENSED", "scripts": { From 129709729aaae807cbcb932cfaff22ad0165ceb7 Mon Sep 17 00:00:00 2001 From: Taly Date: Fri, 3 Sep 2021 14:43:10 +0300 Subject: [PATCH 8/9] test --- index.ts | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/index.ts b/index.ts index aa4c8705..abed6441 100644 --- a/index.ts +++ b/index.ts @@ -10,7 +10,7 @@ if (process.env.HAWK_CATCHER_TOKEN) { release: `${name}-${version}`, }); - HawkCatcher.send(new Error('API is started')); + HawkCatcher.send(new Error(`API is started ${new Date()}`)); } const app = new HawkAPI(); diff --git a/package.json b/package.json index cdcc07a9..6a61cfeb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "hawk.api", - "version": "1.0.2", + "version": "1.0.3", "main": "index.ts", "license": "UNLICENSED", "scripts": { From befbb85f389c6e2eb3ce9dd611e299664cade8f1 Mon Sep 17 00:00:00 2001 From: Taly Date: Fri, 3 Sep 2021 19:16:23 +0300 Subject: [PATCH 9/9] remove log --- .github/workflows/build-and-push-docker-image.yml | 1 - index.ts | 2 -- 2 files changed, 3 deletions(-) diff --git a/.github/workflows/build-and-push-docker-image.yml b/.github/workflows/build-and-push-docker-image.yml index 7dd2c592..2af5c8aa 100644 --- a/.github/workflows/build-and-push-docker-image.yml +++ b/.github/workflows/build-and-push-docker-image.yml @@ -17,7 +17,6 @@ jobs: - name: Checkout repository uses: actions/checkout@v2 - # Get package new version name - name: Get package info id: packageInfo uses: codex-team/action-nodejs-package-info@v1 diff --git a/index.ts b/index.ts index abed6441..aa164117 100644 --- a/index.ts +++ b/index.ts @@ -9,8 +9,6 @@ if (process.env.HAWK_CATCHER_TOKEN) { token: process.env.HAWK_CATCHER_TOKEN, release: `${name}-${version}`, }); - - HawkCatcher.send(new Error(`API is started ${new Date()}`)); } const app = new HawkAPI();