publish-npm-packages #141
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: publish-npm-packages | |
| on: | |
| workflow_dispatch: | |
| jobs: | |
| publish-packages: | |
| runs-on: ubuntu-latest | |
| env: | |
| TEST_ENDPOINT: dapp-example.onekeytest.com | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/setup-node@v4 | |
| with: | |
| node-version: 24 | |
| registry-url: 'https://registry.npmjs.org' | |
| cache: 'yarn' | |
| - name: auto getting release version | |
| id: release_version | |
| run: | | |
| VERSION=$(node -p "require('./packages/core/package.json').version") | |
| if [ -z "$VERSION" ]; then | |
| echo "can't read version" >&2 | |
| exit 1 | |
| fi | |
| echo "version:$VERSION" | |
| echo "version=$VERSION" >> $GITHUB_OUTPUT | |
| echo "VERSION=$VERSION" >> $GITHUB_ENV | |
| - name: Install Packages | |
| # global env make ci `yarn && yarn bootstrap` not correctly | |
| # fix src/classes.ts(2,27): error TS2307: Cannot find module 'fast-safe-stringify' | |
| # exec `yarn bootstrap` twice | |
| run: | | |
| yarn | |
| yarn bootstrap | |
| yarn bootstrap | |
| NODE_ENV=production yarn build | |
| yarn test | |
| yarn lint | |
| cd packages/injected && yarn lint:dist && cd - | |
| - name: Publish | |
| env: | |
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
| # TODO check published packages injected is minified | |
| run: | | |
| git reset --hard | |
| NODE_ENV=production yarn publish-packages -y --no-verify-access | |
| - name: Sleep for 90 seconds | |
| uses: jakejarvis/wait-action@master | |
| with: | |
| time: '90s' | |
| - name: Write Example .env | |
| run: | | |
| # Next.js environment variables | |
| echo "NEXT_PUBLIC_WALLET_CONNECT_PROJECT_ID=${{ secrets.WALLET_CONNECT_PROJECT_ID }}" > ./packages/example/.env | |
| echo "NEXT_PUBLIC_BLOCKFROST_CARDANO_PROJECT_ID=${{ secrets.BLOCKFROST_CARDANO_PROJECT_ID }}" >> ./packages/example/.env | |
| echo "NEXT_PUBLIC_OKLINK_API_KEY=${{ secrets.OKLINK_API_KEY }}" >> ./packages/example/.env | |
| - name: Build Example Web | |
| run: | | |
| yarn clean-workspace | |
| yarn example-build | |
| cp ./packages/example/out/index.html ./packages/example/out/404.html | |
| - name: Deploy Github Pages | |
| uses: peaceiris/actions-gh-pages@v4 | |
| with: | |
| github_token: ${{ secrets.GITHUB_TOKEN }} | |
| publish_dir: ./packages/example/out | |
| cname: ${{ env.TEST_ENDPOINT }} | |
| force_orphan: true | |
| - name: Check if stable release | |
| id: check_stable | |
| run: | | |
| VERSION="${VERSION}" | |
| LOWER_VERSION=$(echo "$VERSION" | tr '[:upper:]' '[:lower:]') | |
| if [[ "$LOWER_VERSION" =~ alpha|beta|rc|canary|dev|next|apache ]]; then | |
| echo "is_stable=false" >> $GITHUB_OUTPUT | |
| echo "Skipping release: $VERSION is a pre-release version" | |
| else | |
| echo "is_stable=true" >> $GITHUB_OUTPUT | |
| echo "Creating release for stable version: $VERSION" | |
| fi | |
| - name: Get previous tag | |
| if: steps.check_stable.outputs.is_stable == 'true' | |
| id: previoustag | |
| run: | | |
| PREV_TAG=$(git describe --tags --abbrev=0 --match "v*" 2>/dev/null || echo "") | |
| echo "tag=$PREV_TAG" >> $GITHUB_OUTPUT | |
| - name: Generate Release Notes | |
| if: steps.check_stable.outputs.is_stable == 'true' | |
| id: release_notes | |
| run: | | |
| VERSION="v${{ env.VERSION }}" | |
| PREV_TAG="${{ steps.previoustag.outputs.tag }}" | |
| echo "## What's Changed" > release_notes.md | |
| echo "" >> release_notes.md | |
| if [ -n "$PREV_TAG" ]; then | |
| echo "### Commits since $PREV_TAG" >> release_notes.md | |
| git log ${PREV_TAG}..HEAD --pretty=format:"- %s (%h)" >> release_notes.md | |
| else | |
| echo "### Recent Commits" >> release_notes.md | |
| git log -20 --pretty=format:"- %s (%h)" >> release_notes.md | |
| fi | |
| echo "" >> release_notes.md | |
| echo "" >> release_notes.md | |
| echo "**Full Changelog**: https://github.com/${{ github.repository }}/compare/${PREV_TAG}...${VERSION}" >> release_notes.md | |
| - name: Create Git Tag | |
| if: steps.check_stable.outputs.is_stable == 'true' | |
| run: | | |
| VERSION="v${{ env.VERSION }}" | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git tag -a $VERSION -m "Release $VERSION" | |
| git push origin $VERSION | |
| - name: Create GitHub Release | |
| if: steps.check_stable.outputs.is_stable == 'true' | |
| uses: softprops/action-gh-release@v1 | |
| with: | |
| tag_name: v${{ env.VERSION }} | |
| name: Release v${{ env.VERSION }} | |
| body_path: release_notes.md | |
| draft: false | |
| prerelease: false | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |