From 6c81227c51114aa760a75fb29c49e7bbaf01b2e4 Mon Sep 17 00:00:00 2001 From: Tiago Barbosa Date: Fri, 29 Sep 2023 14:11:07 +0100 Subject: [PATCH] ci: :wrench: adding github action to publish package on new release replacing old action that was not working due to github permissions on locked branch --- .github/workflows/on_release_created.yml | 46 +++++++++++++++++++++++ .github/workflows/publish.yml | 47 ------------------------ 2 files changed, 46 insertions(+), 47 deletions(-) create mode 100644 .github/workflows/on_release_created.yml delete mode 100644 .github/workflows/publish.yml diff --git a/.github/workflows/on_release_created.yml b/.github/workflows/on_release_created.yml new file mode 100644 index 0000000..875d851 --- /dev/null +++ b/.github/workflows/on_release_created.yml @@ -0,0 +1,46 @@ +name: On Release Created + +on: + release: + types: [created] + +jobs: + # check if the release version contains "beta" + check_if_beta: + runs-on: ubuntu-latest + steps: + - name: Check if beta + id: check_if_beta + run: echo ::set-output name=is_beta::$(echo "${{ github.event.release.tag_name}}" | grep -q "beta" && echo "true" || echo "false") + + # publish to npm with the tag "beta" if the release version contains "beta" otherwise publish with the tag "latest" + publish_to_npm: + needs: check_if_beta + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v3 + - name: Setup Node 18 + uses: actions/setup-node@v3 + with: + node-version: 18 + registry-url: 'https://registry.npmjs.org' + - name: Install yarn + run: corepack enable + - name: Set yarn version to latest stable + run: corepack prepare yarn@stable --activate + - name: Install dependencies + run: yarn install + - name: lint + run: yarn lint + - name: Build + run: yarn build + - name: Replace Action + uses: datamonsters/replace-action@v2 + with: + files: ./.yarnrc.yml + replacements: NPM_TOKEN=${{secrets.npm_token}} + - name: Publish beta version to NPM (uses package.json version) + run: yarn npm publish --tag ${{ steps.check_if_beta.outputs.is_beta == 'true' && 'beta' || 'latest' }} --access public + + \ No newline at end of file diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml deleted file mode 100644 index fc73a51..0000000 --- a/.github/workflows/publish.yml +++ /dev/null @@ -1,47 +0,0 @@ -# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created -# For more information see: https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages - -name: Release - -on: - push: - branches: - - main - -jobs: - release: - runs-on: ubuntu-latest - steps: - - name: Checkout code - uses: actions/checkout@v3 - - name: Setup Node 18 - uses: actions/setup-node@v3 - with: - node-version: 18 - registry-url: 'https://registry.npmjs.org' - - name: Install yarn - run: corepack enable - - name: Set yarn version to latest stable - run: corepack prepare yarn@stable --activate - - name: Install dependencies - run: yarn install - - name: install semantic-release extra plugins - run: yarn add -D @semantic-release/changelog @semantic-release/git @semantic-release/github semantic-release-yarn - - name: lint - run: yarn lint - - name: Build - run: yarn build - # - name: Replace Action - # uses: datamonsters/replace-action@v2 - # with: - # files: ./.yarnrc.yml - # replacements: NPM_TOKEN=${{secrets.npm_token}} - - name: Release - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - NPM_TOKEN: ${{ secrets.NPM_TOKEN }} - YARN_NPM_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} - YARN_NPM_PUBLISH_REGISTRY: https://registry.npmjs.org - run: npx semantic-release - # - name: Publish beta version to NPM (uses package.json version) - # run: yarn npm publish --tag stable --access public