From c9959bcf970ba272180c93747c4ffbf7e5260183 Mon Sep 17 00:00:00 2001 From: ricki-epsilla Date: Mon, 4 Dec 2023 22:37:46 +0800 Subject: [PATCH] test cicd; --- .github/workflows/npm-build-publish.yml | 52 +++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 .github/workflows/npm-build-publish.yml diff --git a/.github/workflows/npm-build-publish.yml b/.github/workflows/npm-build-publish.yml new file mode 100644 index 0000000..42acea3 --- /dev/null +++ b/.github/workflows/npm-build-publish.yml @@ -0,0 +1,52 @@ +name: Build and Publish to npm + +on: + push: + branches: + - main + +jobs: + build-and-test: + runs-on: ubuntu-latest + strategy: + matrix: + node-version: ['14.x', '16.x', '20.4.0'] + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Setup Node.js + uses: actions/setup-node@v2 + with: + node-version: ${{ matrix.node-version }} + registry-url: 'https://registry.npmjs.org' + + - name: Extract version from package.json + id: package_version + run: echo "::set-output name=VERSION::$(node -p "require('./package.json').version")" + + - name: Check if version already published + run: | + VERSION=${{ steps.package_version.outputs.VERSION }} + if npm view epsillajs@$VERSION; then + echo "Version $VERSION already exists on npm. Please update the version." + exit 1 + fi + + - name: Install dependencies + run: npm install + + - name: Build + run: npm run build + + - name: Bump version and push tag + uses: mathieudutour/github-tag-action@v6.1 + with: + github_token: ${{ secrets.PAT_TOKEN }} + tag_prefix: "" + custom_tag: ${{ steps.package_version.outputs.VERSION }} + + - name: Publish to npm + run: npm publish + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_ACCESS_TOKEN }}