diff --git a/.github/workflows/publish-latest.yml b/.github/workflows/publish-latest.yml deleted file mode 100644 index b67eb9d..0000000 --- a/.github/workflows/publish-latest.yml +++ /dev/null @@ -1,39 +0,0 @@ -name: Publish to latest Tag - -on: - push: - branches: - - v1.X - -jobs: - run-publish: - name: Run publish - runs-on: ubuntu-latest - - permissions: - actions: write - - steps: - - name: Check out git repository - uses: actions/checkout@v3 - - - name: Set up Node.js - uses: actions/setup-node@v3 - with: - node-version: lts/* - cache: "yarn" - registry-url: 'https://registry.npmjs.org' - - - name: Install yarn dependencies - run: yarn install - - - name: Build - run: yarn build - - - name: Test - run: yarn test - - - name: Publish - run: yarn publish:latest - env: - NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/publish-next.yml b/.github/workflows/publish-next.yml deleted file mode 100644 index ca02d19..0000000 --- a/.github/workflows/publish-next.yml +++ /dev/null @@ -1,39 +0,0 @@ -name: Publish to next Tag - -on: - push: - branches: - - main - -jobs: - run-publish: - name: Run publish - runs-on: ubuntu-latest - - permissions: - actions: write - - steps: - - name: Check out git repository - uses: actions/checkout@v3 - - - name: Set up Node.js - uses: actions/setup-node@v3 - with: - node-version: lts/* - cache: "yarn" - registry-url: 'https://registry.npmjs.org' - - - name: Install yarn dependencies - run: yarn install - - - name: Build - run: yarn build - - - name: Test - run: yarn test - - - name: Publish - run: yarn publish:next - env: - NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..45b1064 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,55 @@ +name: Publish + +on: + push: + branches: + - main + - v1.X + +jobs: + run-publish: + name: Run publish + runs-on: ubuntu-latest + + permissions: + contents: read + actions: write + + steps: + - name: Check out git repository + uses: actions/checkout@v4 + + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: lts/* + cache: 'yarn' + registry-url: 'https://registry.npmjs.org' + + - name: Install yarn dependencies + run: yarn install + + - name: Build + run: yarn build + + - name: Test + run: yarn test + + - name: Check version and publish + run: | + PACKAGE_NAME=$(node -p "require('./package.json').name") + CURRENT_VERSION=$(node -p "require('./package.json').version") + + # Check if version exists in npm registry + if npm view "${PACKAGE_NAME}@${CURRENT_VERSION}" version &>/dev/null; then + echo "Version $CURRENT_VERSION already published, skipping" + exit 0 + fi + + if [[ "$CURRENT_VERSION" =~ (next) ]]; then + yarn publish:next + else + yarn publish:latest + fi + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}