diff --git a/.github/workflows/release-commit.yml b/.github/workflows/release-commit.yml index 86898200f..4e37ec9b8 100644 --- a/.github/workflows/release-commit.yml +++ b/.github/workflows/release-commit.yml @@ -27,7 +27,7 @@ jobs: create-release-commit: needs: build runs-on: ubuntu-latest - steps: + steps: - name: Checkout code uses: actions/checkout@v4 with: @@ -41,11 +41,11 @@ jobs: - name: Install dependencies run: npm ci - - - name: Initalize git user email - run: git config --global user.email "${{vars.RELEASE_USER_EMAIL}}" - - name: Initalize git user name + - name: Initialize git user email + run: git config --global user.email "${{ vars.RELEASE_USER_EMAIL }}" + + - name: Initialize git user name run: git config --global user.name "Release commit workflow" - name: Create release branch @@ -53,15 +53,14 @@ jobs: git checkout -b $PR_BRANCH_NAME git push --set-upstream origin $PR_BRANCH_NAME echo "branch=$PR_BRANCH_NAME" >> $GITHUB_ENV - + - name: Bump version and push changes using release-it run: | npm run release -- --ci ${{github.event.release.tag_name}} env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - + - name: Create pull request run: gh pr create -B ${{ github.event.repository.default_branch }} -H $PR_BRANCH_NAME --title "Release ${{github.event.release.tag_name}}" --body "${{github.event.release.body}}" env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - \ No newline at end of file + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/release-publish.yml b/.github/workflows/release-publish.yml index c4848dd36..6a20b948b 100644 --- a/.github/workflows/release-publish.yml +++ b/.github/workflows/release-publish.yml @@ -3,6 +3,7 @@ on: push: branches: - release + jobs: build: runs-on: ubuntu-latest @@ -13,6 +14,7 @@ jobs: node-version: 18 - run: npm ci - run: npm test + publish-npm: needs: build runs-on: ubuntu-latest @@ -21,6 +23,7 @@ jobs: uses: actions/checkout@v4 with: ref: main + - name: Setup Node.js uses: actions/setup-node@v4 with: @@ -29,28 +32,44 @@ jobs: - name: Install dependencies run: npm ci - - name: Initalize git user email - run: git config --global user.email "${{env.RELEASE_USER_EMAIL}}" - - name: Initalize git user name + + - name: Initialize git user email + run: git config --global user.email "${{ env.RELEASE_USER_EMAIL }}" + + - name: Initialize git user name run: git config --global user.name "Release publish workflow" - name: Initialize npm config run: npm config set //registry.npmjs.org/:_authToken $NPM_TOKEN env: - NPM_TOKEN: ${{secrets.NPM_TOKEN}} - - name: Check if release is a pre-release - id: check_pre_release - run: echo "{name}=${{github.event.release.prerelease}}" >> $GITHUB_OUTPUT - - - name: Publish to npm - if: steps.check_pre_release.outputs.is_pre_release == 'true' + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} + + - name: Fetch latest release info + run: | + RELEASE_JSON=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ + "https://api.github.com/repos/${{ github.repository }}/releases") + + if [ $? -ne 0 ]; then + echo "Failed to fetch releases" + exit 1 + fi + + LATEST_RELEASE_NAME=$(echo "$RELEASE_JSON" | jq -r '.[0].name') + IS_PRE_RELEASE=$(echo "$RELEASE_JSON" | jq -r '.[0].prerelease') + + echo "LATEST_RELEASE_NAME=$LATEST_RELEASE_NAME" >> $GITHUB_ENV + echo "IS_PRE_RELEASE=$IS_PRE_RELEASE" >> $GITHUB_ENV + + - name: Publish to npm (pre-release) + if: env.IS_PRE_RELEASE == 'true' run: npm publish --tag beta env: - GITHUB_TOKEN: ${{secrets.github_token}} - NODE_AUTH_TOKEN: ${{secrets.npm_token}} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} + - name: Publish to npm - if: steps.check_pre_release.outputs.is_pre_release != 'true' + if: env.IS_PRE_RELEASE == 'false' run: npm publish env: - GITHUB_TOKEN: ${{secrets.github_token}} - NODE_AUTH_TOKEN: ${{secrets.npm_token}} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} \ No newline at end of file