From 3c6f5422160301bd33bee39841e87cfa66cd8fd4 Mon Sep 17 00:00:00 2001 From: Thomas Chaplin Date: Fri, 28 Jul 2023 13:48:29 +0100 Subject: [PATCH] [EE-1663] migrate from jenkins to gha (#74) * migrate from jenkins to gha * update * update readme --- .github/workflows/npm-publish.yml | 63 ++++++++++++++++++++++++++++++ .github/workflows/pull-request.yml | 31 +++++++++++++++ .nvmrc | 1 + README.md | 31 +++++++++------ publish.Jenkinsfile | 40 ------------------- scripts/publish.sh | 31 --------------- 6 files changed, 114 insertions(+), 83 deletions(-) create mode 100644 .github/workflows/npm-publish.yml create mode 100644 .github/workflows/pull-request.yml create mode 100644 .nvmrc delete mode 100644 publish.Jenkinsfile delete mode 100755 scripts/publish.sh diff --git a/.github/workflows/npm-publish.yml b/.github/workflows/npm-publish.yml new file mode 100644 index 0000000..392f154 --- /dev/null +++ b/.github/workflows/npm-publish.yml @@ -0,0 +1,63 @@ +name: NPM Publish + +on: + workflow_dispatch: + inputs: + semver: + description: 'Semantic Version' + required: true + type: choice + options: + - patch + - minor + - major + +concurrency: + group: npm-publish + +jobs: + publish: + runs-on: ubuntu-latest + + permissions: + contents: write + pull-requests: write + + steps: + - name: Checkout + uses: actions/checkout@v3 + + - uses: actions/setup-node@v3 + with: + node-version-file: .nvmrc + cache: npm + + - name: Configure GIT User + run: | + git config --global user.email "GHA@tray.io" + git config --global user.name "Tray.io GHA" + + - name: Login to NPM + run: npm config set //registry.npmjs.org/:_authToken=${{ secrets.CONNECTOR_UTILS_NPM_TOKEN }} + + - name: Install + run: npm ci + + - name: Bump version + run: npm version ${{ inputs.semver }} + + - name: Publish to NPM + run: npm publish + + - name: Push Tags + run: git push --tags + + - name: Create a Pull Request with the new version + uses: peter-evans/create-pull-request@v4 + with: + token: ${{ github.token }} + title: '[EE-1663] Update package version from npm publish' + body: 'These changes were automatically produced by the "NPM Publish" workflow' + base: master + branch: gha/EE-1663/update-lock-file-from-npm-publish + commit-message: Update package version from npm publish diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml new file mode 100644 index 0000000..df2df6e --- /dev/null +++ b/.github/workflows/pull-request.yml @@ -0,0 +1,31 @@ +name: Pull Request + +on: + push: + branches: + - '**' + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + test: + runs-on: ubuntu-latest + + timeout-minutes: 5 + + steps: + - name: Checkout + uses: actions/checkout@v3 + + - uses: actions/setup-node@v3 + with: + node-version-file: .nvmrc + cache: npm + + - name: Install + run: npm ci + + - name: Test + run: npm test diff --git a/.nvmrc b/.nvmrc new file mode 100644 index 0000000..f599e28 --- /dev/null +++ b/.nvmrc @@ -0,0 +1 @@ +10 diff --git a/README.md b/README.md index 1143721..83a5491 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,13 @@ A full breakdown of available utilities is included in the documentation below. Please be sure to add any discovered issues or improvement recommendations to the `Issues` tab of this repo. +## Deploying + +Once a PR is merged into master, you will need to go into GitHub Actions UI and trigger the `NPM Publish` workflow manually providing the input of `major`, `minor` or `patch` depending on what version bump you want to publish - this will automatically build, tag, and publish the new version. + +Once the pipeline is done, a github tag will appear with the new version number. You will need to merge in the automatically generated pull request which bumps the package version. You can then use this tag to create a Github release with some release notes. + + # Documentation ## Classes @@ -143,16 +150,16 @@ for arrays).

Class representing the base error for all connector errors -**Kind**: global class -**Extends**: Error +**Kind**: global class +**Extends**: Error ## UserInputError ⇐ [GenericError](#GenericError) Class representing a UserInputError -**Kind**: global class -**Extends**: [GenericError](#GenericError) +**Kind**: global class +**Extends**: [GenericError](#GenericError) ### new UserInputError(message, ...errorArgs) @@ -170,8 +177,8 @@ Custom error to throw for issues concerning User Input. Class representing a ConnectorError -**Kind**: global class -**Extends**: [GenericError](#GenericError) +**Kind**: global class +**Extends**: [GenericError](#GenericError) ### new ConnectorError(message, ...errorArgs) @@ -189,8 +196,8 @@ Custom error to throw for issues concerning the Connector. Class representing a ConnectorError -**Kind**: global class -**Extends**: [GenericError](#GenericError) +**Kind**: global class +**Extends**: [GenericError](#GenericError) ### new ApiError(message, ...errorArgs) @@ -208,8 +215,8 @@ Custom error to throw for issues concerning the Api;;. Class representing a ConnectorError -**Kind**: global class -**Extends**: [GenericError](#GenericError) +**Kind**: global class +**Extends**: [GenericError](#GenericError) ### new OAuthRefresh(message, ...errorArgs) @@ -227,8 +234,8 @@ Custom error to throw when an oAuth token has expired. Class representing a ConnectorError -**Kind**: global class -**Extends**: [GenericError](#GenericError) +**Kind**: global class +**Extends**: [GenericError](#GenericError) ### new NoTriggerError(message, ...errorArgs) diff --git a/publish.Jenkinsfile b/publish.Jenkinsfile deleted file mode 100644 index 4aab350..0000000 --- a/publish.Jenkinsfile +++ /dev/null @@ -1,40 +0,0 @@ -def authenticateNpm(String npmToken) { - sh(String.format("npm config set //registry.npmjs.org/:_authToken=%s -q", npmToken)) -} - -pipeline { - agent { - docker { - image "tray/node:10" - } - } - - environment { - NPM_TOKEN = credentials("NPM_PUBLISH_TOKEN") - } - - stages { - - stage("Install dependencies") { - steps { - authenticateNpm(env.NPM_TOKEN) - sh("npm ci") - } - } - - stage("Publish packages") { - steps { - sshagent(["1a0031cf-e5b8-4c00-b6cb-b7e214edb435"]) { - sh("bash ./scripts/publish.sh") - } - } - } - } - - options { - timeout(time: 5, unit: "MINUTES") - timestamps() - ansiColor("xterm") - disableConcurrentBuilds() - } -} diff --git a/scripts/publish.sh b/scripts/publish.sh deleted file mode 100755 index fe7337a..0000000 --- a/scripts/publish.sh +++ /dev/null @@ -1,31 +0,0 @@ -#!/usr/bin/env bash - -set -xe - -allowUnknownKeyHostsPairsInGit() { - export GIT_SSH_COMMAND="ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no" -} - -checkIfAlreadyPublished() { - name=$(node -pe "require('./package.json').name") - latestVersion=$(npm show $name:latest version) - if [ "$latestVersion" == "$version" ]; then - echo "Version $version is already the latest published version" - exit 0 - fi -} - -publish() { - npm publish -} - -tag() { - git tag $version - git push origin tags/$version -} -version=$(node -pe "require('./package.json').version") -checkIfAlreadyPublished -allowUnknownKeyHostsPairsInGit - -publish -tag