From 7a8358e627b5fc0b441ec7b4916d9489fdecc509 Mon Sep 17 00:00:00 2001 From: rddimon Date: Thu, 9 Feb 2023 19:43:26 +0200 Subject: [PATCH] Set main branch as default and update GitHub actions --- .github/workflows/publish.yml | 65 ++++++++++++++++++++++++ .github/workflows/test-build-publish.yml | 54 -------------------- .github/workflows/test.yml | 23 +++++++++ README.md | 4 +- 4 files changed, 90 insertions(+), 56 deletions(-) create mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test-build-publish.yml create mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 00000000..bd475f01 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,65 @@ +name: Test, Lint, Release and Publish +on: + push: + branches: + - main +jobs: + main: + name: Release and publish Node package + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Install and test + uses: actions/setup-node@v3 + with: + node-version: 16.x + registry-url: 'https://registry.npmjs.org' + - run: npm install + - run: npm run build + - run: npm run lint + - run: npm test + + - name: Extract version + id: extract_version + uses: Saionaro/extract-package-version@v1.2.1 + + - name: Get latest tag + id: get_latest_tag + uses: actions-ecosystem/action-get-latest-tag@v1 + + - name: See if version changed + run: | + if [[ "v${{ steps.extract_version.outputs.version }}" == "${{ steps.get_latest_tag.outputs.tag }}" ]]; then + echo "VERSION_CHANGED=false" >> "$GITHUB_ENV" + else + echo "VERSION_CHANGED=true" >> "$GITHUB_ENV" + fi + + - name: Create tag + uses: rickstaa/action-create-tag@v1 + if: env.VERSION_CHANGED == 'true' + with: + tag: "v${{ steps.extract_version.outputs.version }}" + + - name: Create release + if: env.VERSION_CHANGED == 'true' + uses: softprops/action-gh-release@v1 + with: + tag_name: 'v${{ steps.extract_version.outputs.version }}' + generate_release_notes: 1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Publish new version + if: env.VERSION_CHANGED == 'true' + # Note: Setting NODE_AUTH_TOKEN as job|workspace wide env var won't work + # as it appears actions/setup-node sets own value + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} + run: npm publish --verbose + + - name: Print dirs + if: failure() + run: find /home/runner/.npm/_logs/ -type f -exec cat {} \; diff --git a/.github/workflows/test-build-publish.yml b/.github/workflows/test-build-publish.yml deleted file mode 100644 index 06cbff99..00000000 --- a/.github/workflows/test-build-publish.yml +++ /dev/null @@ -1,54 +0,0 @@ -name: Test and Optionally Publish -on: - push: - branches: - - master - pull_request: - types: - - opened - - reopened - - synchronize -jobs: - test: - runs-on: ubuntu-latest - strategy: - matrix: - node-version: [ 14.x, 16.x, 18.x ] - steps: - - uses: actions/checkout@master - - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v2 - with: - node-version: ${{ matrix.node-version }} - cache: 'npm' - - run: npm install - - run: npm run lint - - run: npm test - - build-publish: - name: Build and publish Node package - runs-on: ubuntu-latest - needs: [test] - if: github.ref == 'refs/heads/master' - steps: - - name: Checkout repository - uses: actions/checkout@master - - - name: Install Node.js and npm - uses: actions/setup-node@v2 - with: - node-version: 14.x - registry-url: 'https://registry.npmjs.org' - - run: npm install - - run: npm run build - - - name: Publish new version - # Note: Setting NODE_AUTH_TOKEN as job|workspace wide env var won't work - # as it appears actions/setup-node sets own value - env: - NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} - run: npm publish --verbose - - - name: Print dirs - if: failure() - run: find /home/runner/.npm/_logs/ -type f -exec cat {} \; diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 00000000..e5914e08 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,23 @@ +name: Test and Optionally Publish +on: + pull_request: + types: + - opened + - reopened + - synchronize +jobs: + test: + runs-on: ubuntu-latest + strategy: + matrix: + node-version: [ 14.x, 16.x, 18.x ] + steps: + - uses: actions/checkout@v3 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node-version }} + cache: 'npm' + - run: npm install + - run: npm run lint + - run: npm test diff --git a/README.md b/README.md index 3ebac69e..d576ec41 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ # serverless-domain-manager [![serverless](http://public.serverless.com/badges/v3.svg)](http://www.serverless.com) -[![Build Status](https://travis-ci.org/amplify-education/serverless-domain-manager.svg?branch=master)](https://travis-ci.org/amplify-education/serverless-domain-manager) +[![Build Status](https://travis-ci.org/amplify-education/serverless-domain-manager.svg?branch=main)](https://travis-ci.org/amplify-education/serverless-domain-manager) [![npm version](https://badge.fury.io/js/serverless-domain-manager.svg)](https://badge.fury.io/js/serverless-domain-manager) -[![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/amplify-education/serverless-domain-manager/master/LICENSE) +[![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/amplify-education/serverless-domain-manager/main/LICENSE) [![Codacy Badge](https://app.codacy.com/project/badge/Grade/235fe249b8354a3db0cc5926dba47899)](https://www.codacy.com/gh/amplify-education/serverless-domain-manager/dashboard?utm_source=github.com&utm_medium=referral&utm_content=amplify-education/serverless-domain-manager&utm_campaign=Badge_Grade) [![npm downloads](https://img.shields.io/npm/dt/serverless-domain-manager.svg?style=flat)](https://www.npmjs.com/package/serverless-domain-manager)