-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci: update workflows for nodejs projects
- Loading branch information
asyncapi-bot
committed
Jul 12, 2022
1 parent
8eb1be6
commit 0f76362
Showing
4 changed files
with
264 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# This action is centrally managed in https://github.com/asyncapi/.github/ | ||
# Don't make changes to this file in this repo as they will be overwritten with changes made to the same file in above mentioned repo | ||
|
||
# Purpose of this action is to update npm package in libraries that use it. It is like dependabot for asyncapi npm modules only. | ||
# It runs in a repo after merge of release commit and searches for other packages that use released package. Every found package gets updated with lates version | ||
|
||
name: Bump package version in dependent repos - if Node project | ||
|
||
on: | ||
# It cannot run on release event as when release is created then version is not yet bumped in package.json | ||
# This means we cannot extract easily latest version and have a risk that package is not yet on npm | ||
push: | ||
branches: | ||
- master | ||
|
||
jobs: | ||
bump-in-dependent-projects: | ||
name: Bump this package in repositories that depend on it | ||
if: startsWith(github.event.commits[0].message, 'chore(release):') | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout repo | ||
uses: actions/checkout@v2 | ||
- name: Check if Node.js project and has package.json | ||
id: packagejson | ||
run: test -e ./package.json && echo "::set-output name=exists::true" || echo "::set-output name=exists::false" | ||
- if: steps.packagejson.outputs.exists == 'true' | ||
name: Bumping latest version of this package in other repositories | ||
uses: derberg/npm-dependency-manager-for-your-github-org@v4 | ||
with: | ||
github_token: ${{ secrets.GH_TOKEN }} | ||
committer_username: asyncapi-bot | ||
committer_email: info@asyncapi.io | ||
repos_to_ignore: html-template # this is temporary until react component releases 1.0, then it can be removed |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# This action is centrally managed in https://github.com/asyncapi/.github/ | ||
# Don't make changes to this file in this repo as they will be overwritten with changes made to the same file in above mentioned repo | ||
|
||
# It does magic only if there is package.json file in the root of the project | ||
name: PR testing - if Node project | ||
|
||
on: | ||
pull_request: | ||
types: [opened, reopened, synchronize, ready_for_review] | ||
|
||
jobs: | ||
test-nodejs-pr: | ||
name: Test NodeJS PR - ${{ matrix.os }} | ||
runs-on: ${{ matrix.os }} | ||
strategy: | ||
matrix: | ||
os: [ubuntu-latest, macos-latest, windows-latest] | ||
steps: | ||
- if: "github.event.pull_request.draft == false &&!((github.actor == 'asyncapi-bot' && startsWith(github.event.pull_request.title, 'ci: update global workflows')) || (github.actor == 'asyncapi-bot' && startsWith(github.event.pull_request.title, 'chore(release):')) || (github.actor == 'allcontributors' && startsWith(github.event.pull_request.title, 'docs: add')))" | ||
id: should_run | ||
name: Should Run | ||
run: echo "::set-output name=shouldrun::true" | ||
- if: steps.should_run.outputs.shouldrun == 'true' | ||
name: Set git to use LF #to once and for all finish neverending fight between Unix and Windows | ||
run: | | ||
git config --global core.autocrlf false | ||
git config --global core.eol lf | ||
- if: steps.should_run.outputs.shouldrun == 'true' | ||
name: Checkout repository | ||
uses: actions/checkout@v2 | ||
- if: steps.should_run.outputs.shouldrun == 'true' | ||
name: Check if Node.js project and has package.json | ||
id: packagejson | ||
run: test -e ./package.json && echo "::set-output name=exists::true" || echo "::set-output name=exists::false" | ||
shell: bash | ||
- if: steps.packagejson.outputs.exists == 'true' | ||
name: Setup Node.js | ||
uses: actions/setup-node@v2 | ||
with: | ||
node-version: 14 | ||
cache: 'npm' | ||
cache-dependency-path: '**/package-lock.json' | ||
- if: steps.packagejson.outputs.exists == 'true' | ||
name: Install dependencies | ||
id: first-installation | ||
run: npm install --loglevel verbose | ||
continue-on-error: true | ||
- if: steps.first-installation.outputs.status == 'failure' && steps.packagejson.outputs.exists == 'true' | ||
name: Clear NPM cache and install deps again | ||
run: | | ||
npm cache clean --force | ||
npm install --loglevel verbose | ||
- if: steps.packagejson.outputs.exists == 'true' | ||
name: Test | ||
run: npm test | ||
- if: steps.packagejson.outputs.exists == 'true' | ||
name: Run linter | ||
run: npm run lint | ||
- if: steps.packagejson.outputs.exists == 'true' | ||
name: Run release assets generation to make sure PR does not break it | ||
run: npm run generate:assets |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
# This action is centrally managed in https://github.com/asyncapi/.github/ | ||
# Don't make changes to this file in this repo as they will be overwritten with changes made to the same file in above mentioned repo | ||
|
||
# It does magic only if there is package.json file in the root of the project | ||
name: Release - if Node project | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
# below lines are not enough to have release supported for these branches | ||
# make sure configuration of `semantic-release` package mentiones these branches | ||
- next | ||
- next-major | ||
- beta | ||
- alpha | ||
- '**-release' # custom | ||
|
||
jobs: | ||
|
||
test-nodejs: | ||
name: Test NodeJS release on ${{ matrix.os }} | ||
runs-on: ${{ matrix.os }} | ||
strategy: | ||
matrix: | ||
os: [ubuntu-latest, macos-latest, windows-latest] | ||
steps: | ||
- name: Set git to use LF #to once and for all finish neverending fight between Unix and Windows | ||
run: | | ||
git config --global core.autocrlf false | ||
git config --global core.eol lf | ||
- name: Checkout repository | ||
uses: actions/checkout@v2 | ||
- name: Check if Node.js project and has package.json | ||
id: packagejson | ||
run: test -e ./package.json && echo "::set-output name=exists::true" || echo "::set-output name=exists::false" | ||
shell: bash | ||
- if: steps.packagejson.outputs.exists == 'true' | ||
name: Setup Node.js | ||
uses: actions/setup-node@v2 | ||
with: | ||
node-version: 14 | ||
cache: 'npm' | ||
cache-dependency-path: '**/package-lock.json' | ||
- if: steps.packagejson.outputs.exists == 'true' | ||
name: Install dependencies | ||
run: npm install | ||
- if: steps.packagejson.outputs.exists == 'true' | ||
name: Run test | ||
run: npm test | ||
- if: failure() # Only, on failure, send a message on the 94_bot-failing-ci slack channel | ||
name: Report workflow run status to Slack | ||
uses: 8398a7/action-slack@v3 | ||
with: | ||
status: ${{ job.status }} | ||
fields: repo,action,workflow | ||
text: 'Release workflow failed in testing job' | ||
env: | ||
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_CI_FAIL_NOTIFY }} | ||
|
||
release: | ||
needs: [test-nodejs] | ||
name: Publish to any of NPM, Github, and Docker Hub | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Set git to use LF #to once and for all finish neverending fight between Unix and Windows | ||
run: | | ||
git config --global core.autocrlf false | ||
git config --global core.eol lf | ||
- name: Checkout repository | ||
uses: actions/checkout@v2 | ||
- name: Check if Node.js project and has package.json | ||
id: packagejson | ||
run: test -e ./package.json && echo "::set-output name=exists::true" || echo "::set-output name=exists::false" | ||
- if: steps.packagejson.outputs.exists == 'true' | ||
name: Setup Node.js | ||
uses: actions/setup-node@v1 | ||
with: | ||
node-version: 14 | ||
- if: steps.packagejson.outputs.exists == 'true' | ||
name: Install dependencies | ||
run: npm install | ||
- if: steps.packagejson.outputs.exists == 'true' | ||
name: Publish to any of NPM, Github, and Docker Hub | ||
id: release | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }} | ||
NPM_TOKEN: ${{ secrets.NPM_TOKEN }} | ||
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} | ||
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} | ||
GIT_AUTHOR_NAME: asyncapi-bot | ||
GIT_AUTHOR_EMAIL: info@asyncapi.io | ||
GIT_COMMITTER_NAME: asyncapi-bot | ||
GIT_COMMITTER_EMAIL: info@asyncapi.io | ||
run: npm run release | ||
- if: failure() # Only, on failure, send a message on the 94_bot-failing-ci slack channel | ||
name: Report workflow run status to Slack | ||
uses: 8398a7/action-slack@v3 | ||
with: | ||
status: ${{ job.status }} | ||
fields: repo,action,workflow | ||
text: 'Release workflow failed in release job' | ||
env: | ||
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_CI_FAIL_NOTIFY }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# This action is centrally managed in https://github.com/asyncapi/.github/ | ||
# Don't make changes to this file in this repo as they will be overwritten with changes made to the same file in above mentioned repo | ||
|
||
# It does magic only if there is package.json file in the root of the project | ||
name: Version bump - if Node.js project | ||
|
||
on: | ||
release: | ||
types: | ||
- published | ||
|
||
jobs: | ||
version_bump: | ||
name: Generate assets and bump NodeJS | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v2 | ||
with: | ||
# target branch of release. More info https://docs.github.com/en/rest/reference/repos#releases | ||
# in case release is created from release branch then we need to checkout from given branch | ||
# if @semantic-release/github is used to publish, the minimum version is 7.2.0 for proper working | ||
ref: ${{ github.event.release.target_commitish }} | ||
- name: Check if Node.js project and has package.json | ||
id: packagejson | ||
run: test -e ./package.json && echo "::set-output name=exists::true" || echo "::set-output name=exists::false" | ||
- if: steps.packagejson.outputs.exists == 'true' | ||
name: Setup Node.js | ||
uses: actions/setup-node@v2 | ||
with: | ||
node-version: 14 | ||
cache: 'npm' | ||
cache-dependency-path: '**/package-lock.json' | ||
- if: steps.packagejson.outputs.exists == 'true' | ||
name: Install dependencies | ||
run: npm install | ||
- if: steps.packagejson.outputs.exists == 'true' | ||
name: Assets generation | ||
run: npm run generate:assets | ||
- if: steps.packagejson.outputs.exists == 'true' | ||
name: Bump version in package.json | ||
# There is no need to substract "v" from the tag as version script handles it | ||
# When adding "bump:version" script in package.json, make sure no tags are added by default (--no-git-tag-version) as they are already added by release workflow | ||
# When adding "bump:version" script in package.json, make sure --allow-same-version is set in case someone forgot and updated package.json manually and we want to avoide this action to fail and raise confusion | ||
run: VERSION=${{github.event.release.tag_name}} npm run bump:version | ||
- if: steps.packagejson.outputs.exists == 'true' | ||
name: Create Pull Request with updated asset files including package.json | ||
uses: peter-evans/create-pull-request@v3 | ||
with: | ||
token: ${{ secrets.GH_TOKEN }} | ||
commit-message: 'chore(release): ${{github.event.release.tag_name}}' | ||
committer: asyncapi-bot <info@asyncapi.io> | ||
author: asyncapi-bot <info@asyncapi.io> | ||
title: 'chore(release): ${{github.event.release.tag_name}}' | ||
body: 'Version bump in package.json for release [${{github.event.release.tag_name}}](${{github.event.release.html_url}})' | ||
branch: version-bump/${{github.event.release.tag_name}} | ||
- if: failure() # Only, on failure, send a message on the 94_bot-failing-ci slack channel | ||
name: Report workflow run status to Slack | ||
uses: 8398a7/action-slack@v3 | ||
with: | ||
status: ${{ job.status }} | ||
fields: repo,action,workflow | ||
text: 'Unable to bump the version in package.json after the release' | ||
env: | ||
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_CI_FAIL_NOTIFY }} |