Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Pre release workflow #770

Merged
merged 2 commits into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions .github/workflows/release-commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
create-release-commit:
needs: build
runs-on: ubuntu-latest
steps:
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
Expand All @@ -41,27 +41,26 @@ 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
run: |
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 }}

GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
49 changes: 34 additions & 15 deletions .github/workflows/release-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ on:
push:
branches:
- release

jobs:
build:
runs-on: ubuntu-latest
Expand All @@ -13,6 +14,7 @@ jobs:
node-version: 18
- run: npm ci
- run: npm test

publish-npm:
needs: build
runs-on: ubuntu-latest
Expand All @@ -21,6 +23,7 @@ jobs:
uses: actions/checkout@v4
with:
ref: main

- name: Setup Node.js
uses: actions/setup-node@v4
with:
Expand All @@ -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 }}