From 7667a25942342f7074eb87997dc75a429ae5f672 Mon Sep 17 00:00:00 2001 From: Matt Hillsdon Date: Wed, 17 Apr 2024 13:15:48 +0100 Subject: [PATCH 1/2] NPM publish from GHA Align build.yml with similar projects --- .circleci/config.yml | 76 ------------------------------------- .github/workflows/build.yml | 28 +++++++++----- 2 files changed, 19 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..bec0bd2 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,19 +1,29 @@ -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 + packages: write 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 + env: + NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - 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 }} From 8f2f01b4fc4bb096f39dd2f88a755bf3f096f319 Mon Sep 17 00:00:00 2001 From: Matt Hillsdon Date: Wed, 17 Apr 2024 17:31:09 +0100 Subject: [PATCH 2/2] Tweaks based on review --- .github/workflows/build.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index bec0bd2..f331876 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -10,7 +10,6 @@ jobs: runs-on: ubuntu-latest permissions: contents: read - packages: write steps: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 @@ -19,8 +18,6 @@ jobs: registry-url: 'https://registry.npmjs.org' cache: npm - run: npm ci - env: - NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: npm run test:coverage - run: npm run build - run: npm publish