diff --git a/.github/workflows/build-and-publish-main.yaml b/.github/workflows/build-and-publish-main.yaml new file mode 100644 index 0000000..3199431 --- /dev/null +++ b/.github/workflows/build-and-publish-main.yaml @@ -0,0 +1,26 @@ +name: Build and Publish NPM package + +on: + push: + branches: [main] + +jobs: + build-and-publish: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-node@v4 + with: + registry-url: "https://registry.npmjs.org" + + - name: Install dependencies + run: npm ci + + - name: Run build + run: npm run build + + - name: Publish to NPM package registry + run: npm publish + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_PACKAGE_REGISTRY_TOKEN }} diff --git a/.github/workflows/build-and-publish-pr.yaml b/.github/workflows/build-and-publish-pr.yaml new file mode 100644 index 0000000..7f07652 --- /dev/null +++ b/.github/workflows/build-and-publish-pr.yaml @@ -0,0 +1,40 @@ +name: Build and Publish NPM package + +on: + pull_request: + +jobs: + build-and-publish: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-node@v4 + with: + registry-url: "https://registry.npmjs.org" + + - name: Install dependencies + run: npm ci + + - name: Run build + run: npm run build + + - id: current-version + name: Get current version + run: echo "CURRENT_VERSION=$(npm pkg get version | tr -d '"')" >> $GITHUB_OUTPUT + + - id: sha + name: Get commit sha + run: echo "SHA=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT + + - name: Set publish version + run: npm version --no-git-tag-version $CURRENT_VERSION-$SHA + env: + SHA: ${{ steps.sha.outputs.SHA }} + CURRENT_VERSION: ${{ steps.current-version.outputs.CURRENT_VERSION }} + + - name: Publish to NPM package registry + run: npm publish --tag pr-$PR_NUMBER + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_PACKAGE_REGISTRY_TOKEN }} + PR_NUMBER: ${{ github.event.number }} diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml deleted file mode 100644 index f1c259d..0000000 --- a/.github/workflows/build.yaml +++ /dev/null @@ -1,46 +0,0 @@ -name: Publish - -on: - push: - branches: [main] - -jobs: - publish_NPM: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - - uses: actions/setup-node@v4 - with: - registry-url: "https://registry.npmjs.org" - - - name: Install dependencies - run: npm ci - - - name: Run build - run: npm run build - - - name: Publish to NPM package registry - run: npm publish - env: - NODE_AUTH_TOKEN: ${{ secrets.NPM_PACKAGE_REGISTRY_TOKEN }} - - publish_Github: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - - uses: actions/setup-node@v4 - with: - registry-url: "https://npm.pkg.github.com" - - - name: Install dependencies - run: npm ci - - - name: Run build - run: npm run build - - - name: Publish to Github package registry - run: npm publish - env: - NODE_AUTH_TOKEN: ${{ secrets.GH_PACKAGE_REGISTRY_TOKEN }}