From 55bd279e0852e3211bc0c040763dc91089ba999c Mon Sep 17 00:00:00 2001 From: asyncapi-bot <61865014+asyncapi-bot@users.noreply.github.com> Date: Tue, 26 Jan 2021 12:23:27 +0100 Subject: [PATCH] ci: update global workflows (#493) ci: update global workflows --- .github/workflows/if-nodejs-pr-testing.yml | 41 ++++++++++++ .github/workflows/if-nodejs-release.yml | 66 ++++++++++++++++++++ .github/workflows/if-nodejs-version-bump.yml | 45 +++++++++++++ 3 files changed, 152 insertions(+) create mode 100644 .github/workflows/if-nodejs-pr-testing.yml create mode 100644 .github/workflows/if-nodejs-release.yml create mode 100644 .github/workflows/if-nodejs-version-bump.yml diff --git a/.github/workflows/if-nodejs-pr-testing.yml b/.github/workflows/if-nodejs-pr-testing.yml new file mode 100644 index 000000000..b39bfea42 --- /dev/null +++ b/.github/workflows/if-nodejs-pr-testing.yml @@ -0,0 +1,41 @@ +#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: + if: github.event.pull_request.draft == false + name: ${{ matrix.os }} + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-latest, macos-latest, windows-latest] + steps: + - 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@v1 + with: + node-version: 14 + - if: steps.packagejson.outputs.exists == 'true' + name: Install dependencies + run: 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 diff --git a/.github/workflows/if-nodejs-release.yml b/.github/workflows/if-nodejs-release.yml new file mode 100644 index 000000000..7da5645aa --- /dev/null +++ b/.github/workflows/if-nodejs-release.yml @@ -0,0 +1,66 @@ +#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 + +jobs: + + test: + name: Test on ${{ matrix.os }} + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-latest, macos-latest, windows-latest] + steps: + - 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@v1 + with: + node-version: 14 + - if: steps.packagejson.outputs.exists == 'true' + name: Install dependencies + run: npm install + - if: steps.packagejson.outputs.exists == 'true' + name: Run test + run: npm test + + release: + needs: test + name: Publish to NPM and GitHub + runs-on: ubuntu-latest + steps: + - 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: Release to NPM and GitHub + id: release + env: + GITHUB_TOKEN: ${{ secrets.GH_TOKEN }} + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} + 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 \ No newline at end of file diff --git a/.github/workflows/if-nodejs-version-bump.yml b/.github/workflows/if-nodejs-version-bump.yml new file mode 100644 index 000000000..34d57df82 --- /dev/null +++ b/.github/workflows/if-nodejs-version-bump.yml @@ -0,0 +1,45 @@ +#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 + runs-on: ubuntu-latest + steps: + - name: Checkout repo + uses: actions/checkout@v2 + with: + ref: master + - 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: 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 + author: asyncapi-bot + 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}} \ No newline at end of file