From bf695d729f6f4edbfb37efab21b1ef1d451fba4d Mon Sep 17 00:00:00 2001 From: Aswin V Date: Sat, 8 Apr 2023 21:37:29 +0530 Subject: [PATCH] - Publish npm from release branch - Consolidate action into single file --- .../workflows/{npm-publish.yml => main.yml} | 27 ++++++++++++------- .github/workflows/node.js.yml | 25 ----------------- 2 files changed, 18 insertions(+), 34 deletions(-) rename .github/workflows/{npm-publish.yml => main.yml} (75%) delete mode 100644 .github/workflows/node.js.yml diff --git a/.github/workflows/npm-publish.yml b/.github/workflows/main.yml similarity index 75% rename from .github/workflows/npm-publish.yml rename to .github/workflows/main.yml index 3875739..14b36ff 100644 --- a/.github/workflows/npm-publish.yml +++ b/.github/workflows/main.yml @@ -4,8 +4,16 @@ name: Node.js Package on: - release: - types: [created] + push: + branches: + - main + - release + tags: + - "beta-v*" + pull_request: + # Trigger only for PRs that target main branch + branches: + - main jobs: build: @@ -34,21 +42,22 @@ jobs: npm install -g json JACKSON_VERSION=$(echo $(cat package.json) | json version) - # publishTag="latest" + publishTag="latest" - # if [[ "$GITHUB_REF" == *\/release ]] - # then - # echo "Release branch" - # else - echo "Beta release" + if [[ "$GITHUB_REF" == *\/release ]] + then + echo "Release branch" + else + echo "Dev branch" publishTag="beta" JACKSON_VERSION="${JACKSON_VERSION}-beta.${GITHUB_RUN_NUMBER}" - # fi + fi json -I -f package.json -e "this.version=\"${JACKSON_VERSION}\"" echo "NPM_VERSION=${JACKSON_VERSION}" >> $GITHUB_OUTPUT echo "PUBLISH_TAG=${publishTag}" >> $GITHUB_OUTPUT - run: npm publish --tag ${{ steps.version.outputs.PUBLISH_TAG }} --access public + if: github.ref == 'refs/heads/release' || contains(github.ref, 'refs/tags/beta-v') env: NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml deleted file mode 100644 index 20c4f3d..0000000 --- a/.github/workflows/node.js.yml +++ /dev/null @@ -1,25 +0,0 @@ -name: Node.js CI - -on: - push: - branches: [main] - pull_request: - branches: [main] - -jobs: - build: - runs-on: ubuntu-latest - - strategy: - matrix: - node-version: [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 }} - - run: npm ci - - run: npm run build --if-present - - run: npm test --if-present