From 4f63519e46d9880622734e9d914b6d73acdce8a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leonardo=20Quixada=CC=81?= Date: Thu, 1 Jun 2023 11:57:26 -0400 Subject: [PATCH] chore: improved github workflow for v3.x work --- .github/workflows/{ci.yml => branch.yml} | 12 +----- .github/workflows/checks.yml | 26 +++++++++--- .github/workflows/pr.yml | 4 +- .github/workflows/release.yml | 51 ++++++++++++++++++++++-- 4 files changed, 73 insertions(+), 20 deletions(-) rename .github/workflows/{ci.yml => branch.yml} (84%) diff --git a/.github/workflows/ci.yml b/.github/workflows/branch.yml similarity index 84% rename from .github/workflows/ci.yml rename to .github/workflows/branch.yml index 8526379..c7a7641 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/branch.yml @@ -1,11 +1,9 @@ -name: Main Branch +name: v3.x branch on: push: branches: - - v3.x - tags: - - v[0-9]+.[0-9]+.[0-9]+ + - v3.x jobs: install: @@ -44,9 +42,3 @@ jobs: - run: make secure env: SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }} - - release: - name: Release - if: startsWith(github.event.ref, 'refs/tags/') - needs: [checks, security] - uses: ./.github/workflows/release.yml diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml index 7e4ae0f..e62dd6a 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -1,15 +1,15 @@ -name: Checks +name: checks on: [workflow_call] jobs: - test: - name: Test specs + test-node: + name: Node Test Specs runs-on: ubuntu-latest strategy: fail-fast: false matrix: - node-version: [10.x, 12.x, 14.x, 16.x] + node-version: [14.x, 16.x, 18.x, 20.x] # See supported Node.js release schedule at https://nodejs.org/en/about/releases/ steps: - uses: actions/checkout@v3 @@ -22,7 +22,23 @@ jobs: with: node-version: ${{ matrix.node-version }} - run: npm install --prefer-offline - - run: make test + - run: make test-node + + test-browser: + name: Browser Test Specs + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/cache@v3 + with: + path: ~/.npm # this is cache where npm installs from before going out to the network + key: ${{ runner.os }}-node-${{ hashFiles('**/package.json') }} + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node-version }} + - run: npm install --prefer-offline + - run: make test-browser lint: name: Code Lint diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 8938b4d..42eefc0 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -1,4 +1,4 @@ -name: Pull Request +name: v3.x pull requests on: pull_request_target: @@ -6,6 +6,8 @@ on: - opened - edited - synchronize + branches: + - v3.x jobs: prlint: diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 3620573..d376992 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,11 +1,53 @@ -name: Release +name: v3.x release -on: [workflow_call] +on: + push: + tags: + - v3.[0-9]+.[0-9]+ + - v3.[0-9]+.[0-9]+-(alpha|beta).[0-9]+ # prerelease jobs: + install: + name: Install + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Cache node_modules + id: cacheModules + uses: actions/cache@v3 + with: + path: ~/.npm # this is cache where npm installs from before going out to the network + key: ${{ runner.os }}-node-${{ hashFiles('**/package.json') }} + - name: Install dependencies + if: steps.cacheModules.outputs.cache-hit != 'true' + run: npm install + + checks: + name: Check + needs: [install] + uses: ./.github/workflows/checks.yml + + # The security job can't run on pull requests opened from forks because + # Github doesn't pass down the SNYK_TOKEN environment variable. + security: + name: Check Security + needs: [install] + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/cache@v3 + with: + path: ~/.npm # this is cache where npm installs from before going out to the network + key: ${{ runner.os }}-node-${{ hashFiles('**/package.json') }} + - run: npm install --prefer-offline + - run: make secure + env: + SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }} + npm: name: Publish to NPM registry runs-on: ubuntu-latest + needs: [checks, security] steps: - uses: actions/checkout@v3 # Setup .npmrc file to publish to npm @@ -18,13 +60,14 @@ jobs: path: ~/.npm # this is cache where npm installs from before going out to the network key: ${{ runner.os }}-node-${{ hashFiles('**/package.json') }} - run: npm install --prefer-offline - - run: npm publish + - run: npm publish --tag latest-v3.x env: NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} github: name: Publish to Github registry runs-on: ubuntu-latest + needs: [checks, security] steps: - uses: actions/checkout@v3 # Setup .npmrc file to publish to GitHub Packages @@ -39,6 +82,6 @@ jobs: - run: npm install --prefer-offline # The package name needs to be scoped in order to publish on Github Registry - run: sed -i 's/"cross-fetch"/"@lquixada\/cross-fetch"/g' package.json - - run: npm publish + - run: npm publish --tag latest-v3.x env: NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}