From f49e8e6881ce8b8b1c10aed4413eec7f18680995 Mon Sep 17 00:00:00 2001 From: Matt Hillsdon <44397098+microbit-matt-hillsdon@users.noreply.github.com> Date: Thu, 18 Apr 2024 10:16:32 +0100 Subject: [PATCH] CI: NPM publish from GHA (#40) * NPM publish from GHA Align build.yml with similar projects * Tweaks based on review --- .circleci/config.yml | 76 ------------------------------------- .github/workflows/build.yml | 25 +++++++----- 2 files changed, 16 insertions(+), 85 deletions(-) delete mode 100644 .circleci/config.yml diff --git a/.circleci/config.yml b/.circleci/config.yml deleted file mode 100644 index 54391f6..0000000 --- a/.circleci/config.yml +++ /dev/null @@ -1,76 +0,0 @@ -version: 2.1 - -defaults: &defaults - working_directory: ~/repo - docker: - - image: cimg/node:14.19 - -_steps: - restore_npm_cache: &restore_npm_cache - restore_cache: - keys: - - npm-v1-{{ .Branch }}-{{ checksum "package-lock.json" }} - - npm-v1-{{ .Branch }}- - - npm-v1- - save_npm_cache: &save_npm_cache - save_cache: - paths: - - .npm-cache - key: npm-v1-{{ .Branch }}-{{ checksum "package-lock.json" }} - configure_registry_auth: &configure_registry_auth - run: - name: Configure registry auth - command: echo "//registry.npmjs.org/:_authToken=$NPM_AUTH_TOKEN" >> ~/repo/.npmrc - -jobs: - test: - <<: *defaults - steps: - - checkout - - *restore_npm_cache - - *configure_registry_auth - - run: npm ci --cache .npm-cache - - run: - name: Run coverage tests - command: npm run test:coverage - - run: - name: Run build - command: npm run build - - persist_to_workspace: - root: ~/repo - paths: . - - store_artifacts: - path: ~/repo/dist - - *save_npm_cache - deploy: - <<: *defaults - steps: - - attach_workspace: - at: ~/repo - - *configure_registry_auth - - run: - name: Publish package - # For now we only publish on tags here and assume the version number is already correct. - # If we change this then we need to automate updating the version number. - command: npm publish $(if [ -z "$CIRCLE_TAG" ]; then echo "--tag next"; fi) - -workflows: - version: 2 - test-deploy: - jobs: - - test: - context: - - "NPM Read" - filters: - tags: - only: /^v.*/ - - deploy: - context: - - "NPM Write" - requires: - - test - filters: - tags: - only: /^v.*/ - branches: - ignore: /.*/ diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index af879ce..f331876 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,19 +1,26 @@ -name: Test & Build - +name: build on: + release: + types: [created] push: - branches: '*' - pull_request: - branches: '*' - + branches: + - '**' jobs: - test-build: - name: Run tests and build project + build: runs-on: ubuntu-latest + permissions: + contents: read steps: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 with: - node-version: 18 + node-version: '20.x' + registry-url: 'https://registry.npmjs.org' + cache: npm - run: npm ci + - run: npm run test:coverage - run: npm run build + - run: npm publish + if: github.event_name == 'release' && github.event.action == 'created' + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}