Publish packages and create tags #255
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 packages and create tags | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| release_type: | |
| description: "Type of release (auto, prerelease, patch, minor, major)" | |
| required: true | |
| default: "auto" | |
| type: choice | |
| options: | |
| - auto | |
| - prerelease | |
| - patch | |
| - minor | |
| - major | |
| prerelease_tag: | |
| description: "Prerelease tag (e.g., rc, beta, alpha) - only used for prerelease" | |
| required: false | |
| default: "rc" | |
| dry_run: | |
| description: "Dry run (no actual publishing or commits)" | |
| required: false | |
| default: false | |
| type: boolean | |
| jobs: | |
| release: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| submodules: true | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| fetch-depth: 0 | |
| - uses: pnpm/action-setup@v3 | |
| with: | |
| version: 10.0.0 | |
| - name: Setup Node.js with PNPM cache | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: "lts/*" | |
| cache: "pnpm" | |
| # The cache will be invalidated if these files change | |
| cache-dependency-path: "**/pnpm-lock.yaml" | |
| # Cache the PNPM store to speed up installations | |
| - name: Get PNPM store directory | |
| id: pnpm-cache | |
| shell: bash | |
| run: | | |
| echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT | |
| - name: Setup PNPM cache | |
| uses: actions/cache@v3 | |
| with: | |
| path: ${{ steps.pnpm-cache.outputs.STORE_PATH }} | |
| key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} | |
| restore-keys: | | |
| ${{ runner.os }}-pnpm-store- | |
| # Optional: Cache build output for even faster subsequent builds | |
| - name: Cache build output | |
| uses: actions/cache@v3 | |
| with: | |
| path: | | |
| **/dist | |
| **/.turbo | |
| key: ${{ runner.os }}-build-${{ github.sha }} | |
| restore-keys: | | |
| ${{ runner.os }}-build- | |
| # Add Cargo cache for torii-wasm | |
| - name: Cache Cargo dependencies and build artifacts | |
| uses: actions/cache@v3 | |
| with: | |
| path: | | |
| ~/.cargo/registry | |
| ~/.cargo/git | |
| packages/torii-wasm/dojo.c/target | |
| key: ${{ runner.os }}-cargo-${{ hashFiles('packages/torii-wasm/**/Cargo.lock') }} | |
| restore-keys: | | |
| ${{ runner.os }}-cargo- | |
| - run: curl -L https://install.dojoengine.org | bash | |
| - uses: software-mansion/setup-scarb@v1 | |
| with: | |
| scarb-version: "2.10.1" | |
| - run: /home/runner/.config/.dojo/dojoup/dojoup install v1.5.0-alpha.2 | |
| - run: | | |
| cd worlds/dojo-starter | |
| /home/runner/.config/.dojo/bin/sozo build | |
| - run: | | |
| cd worlds/onchain-dash | |
| /home/runner/.config/.dojo/bin/sozo build | |
| - name: Configure Git | |
| run: | | |
| git config user.name "${{ github.actor }}" | |
| git config user.email "${{ github.actor }}@users.noreply.github.com" | |
| - name: Determine release strategy | |
| id: release-strategy | |
| run: | | |
| CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD) | |
| echo "Current branch: $CURRENT_BRANCH" | |
| # Determine if we should use prerelease mode | |
| if [[ "$CURRENT_BRANCH" != "main" && "${{ github.event.inputs.release_type }}" == "auto" ]]; then | |
| echo "Non-main branch detected, will use prerelease mode" | |
| echo "use_prerelease=true" >> $GITHUB_OUTPUT | |
| # Extract version from branch name if it's a release branch | |
| if [[ "$CURRENT_BRANCH" =~ ^release/([0-9]+\.[0-9]+) ]]; then | |
| echo "prerelease_tag=${BASH_REMATCH[1]}-rc" >> $GITHUB_OUTPUT | |
| else | |
| # Use branch name as prerelease tag (sanitized) | |
| SANITIZED_BRANCH=$(echo "$CURRENT_BRANCH" | sed 's/[^a-zA-Z0-9-]/-/g') | |
| echo "prerelease_tag=$SANITIZED_BRANCH" >> $GITHUB_OUTPUT | |
| fi | |
| elif [[ "${{ github.event.inputs.release_type }}" == "prerelease" ]]; then | |
| echo "Manual prerelease requested" | |
| echo "use_prerelease=true" >> $GITHUB_OUTPUT | |
| echo "prerelease_tag=${{ github.event.inputs.prerelease_tag }}" >> $GITHUB_OUTPUT | |
| else | |
| echo "Standard release mode" | |
| echo "use_prerelease=false" >> $GITHUB_OUTPUT | |
| fi | |
| - name: "Setup npm authentication" | |
| run: | | |
| npm config set registry https://registry.npmjs.org/ | |
| npm config set //registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }} | |
| echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > ~/.npmrc | |
| - name: Install Protobuf Compiler | |
| run: sudo apt-get install -y protobuf-compiler | |
| - name: Install dependencies | |
| run: pnpm install | |
| - name: Enter prerelease mode if needed | |
| if: steps.release-strategy.outputs.use_prerelease == 'true' | |
| run: | | |
| PRERELEASE_TAG="${{ steps.release-strategy.outputs.prerelease_tag }}" | |
| echo "Entering prerelease mode with tag: $PRERELEASE_TAG" | |
| if [ "${{ github.event.inputs.dry_run }}" != "true" ]; then | |
| pnpm changeset pre enter "$PRERELEASE_TAG" | |
| else | |
| echo "DRY RUN: Would enter prerelease mode with tag $PRERELEASE_TAG" | |
| fi | |
| - name: Check for changesets | |
| id: check-changesets | |
| run: | | |
| # Check if there are any changesets | |
| if [ -z "$(ls -A .changeset/*.md 2>/dev/null | grep -v README.md)" ]; then | |
| echo "No changesets found. Nothing to release." | |
| echo "has_changesets=false" >> $GITHUB_OUTPUT | |
| exit 0 | |
| else | |
| echo "Found changesets to process." | |
| echo "has_changesets=true" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Version packages | |
| if: steps.check-changesets.outputs.has_changesets == 'true' | |
| id: changesets-version | |
| run: | | |
| echo "Running changeset version..." | |
| if [ "${{ github.event.inputs.dry_run }}" != "true" ]; then | |
| pnpm changeset version | |
| # If we're in prerelease mode and on a non-main branch, we might need to force version bumps | |
| if [ "${{ steps.release-strategy.outputs.use_prerelease }}" == "true" ]; then | |
| echo "Prerelease versioning completed" | |
| fi | |
| else | |
| echo "DRY RUN: Would run changeset version" | |
| # Show what would be versioned | |
| pnpm changeset status --verbose | |
| fi | |
| - name: Commit changes | |
| if: ${{ github.event.inputs.dry_run != 'true' && steps.check-changesets.outputs.has_changesets == 'true' }} | |
| run: | | |
| if git diff --quiet && git diff --staged --quiet; then | |
| echo "No changes to commit" | |
| else | |
| git add . | |
| git commit -m "chore: release" | |
| # Push to the current branch | |
| CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD) | |
| git push origin "refs/heads/$CURRENT_BRANCH:refs/heads/$CURRENT_BRANCH" | |
| fi | |
| - name: Publish to npm | |
| if: ${{ github.event.inputs.dry_run != 'true' && steps.check-changesets.outputs.has_changesets == 'true' }} | |
| run: | | |
| echo "Publishing packages..." | |
| # Changesets will only publish packages that are not ignored in config | |
| pnpm release | |
| env: | |
| NPM_TOKEN: ${{ secrets.NPM_TOKEN }} | |
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
| - name: Dry run - Show npm publish | |
| if: ${{ github.event.inputs.dry_run == 'true' && steps.check-changesets.outputs.has_changesets == 'true' }} | |
| run: | | |
| echo "DRY RUN: Would publish the following packages to npm:" | |
| # Show what changesets would publish | |
| pnpm changeset publish --dry-run | |
| env: | |
| NPM_TOKEN: ${{ secrets.NPM_TOKEN }} | |
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
| - name: Create and push tags | |
| if: ${{ github.event.inputs.dry_run != 'true' && steps.check-changesets.outputs.has_changesets == 'true' }} | |
| run: | | |
| echo "Creating tags..." | |
| pnpm changeset tag | |
| git push --tags | |
| - name: Exit prerelease mode if needed | |
| if: steps.release-strategy.outputs.use_prerelease == 'true' && github.event.inputs.dry_run != 'true' && steps.check-changesets.outputs.has_changesets == 'true' | |
| run: | | |
| echo "Exiting prerelease mode" | |
| pnpm changeset pre exit || true | |
| # Commit the pre.json removal if it exists | |
| if [ -f .changeset/pre.json ]; then | |
| git add .changeset/pre.json | |
| git commit -m "chore: exit prerelease mode" || true | |
| CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD) | |
| git push origin "refs/heads/$CURRENT_BRANCH:refs/heads/$CURRENT_BRANCH" || true | |
| fi | |
| - name: Trigger release creation | |
| if: ${{ github.event.inputs.dry_run != 'true' && steps.check-changesets.outputs.has_changesets == 'true' }} | |
| run: | | |
| # Get all tags that were just created | |
| TAGS=$(git tag --points-at HEAD | grep '@dojoengine/' || true) | |
| # For each tag, trigger the release workflow | |
| CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD) | |
| for TAG in $TAGS; do | |
| echo "Triggering release for tag: $TAG" | |
| gh workflow run create_release.yaml \ | |
| --ref "$CURRENT_BRANCH" \ | |
| -f tag="$TAG" | |
| done | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Dry run - Summary | |
| if: ${{ github.event.inputs.dry_run == 'true' && steps.check-changesets.outputs.has_changesets == 'true' }} | |
| run: | | |
| echo "DRY RUN SUMMARY:" | |
| echo "================" | |
| if [ "${{ steps.release-strategy.outputs.use_prerelease }}" == "true" ]; then | |
| echo "Would enter prerelease mode: ${{ steps.release-strategy.outputs.prerelease_tag }}" | |
| fi | |
| echo "Would version packages according to changesets" | |
| echo "Would commit with message: chore: release" | |
| echo "Would create and push tags" | |
| echo "Would publish packages to npm" | |
| if [ "${{ steps.release-strategy.outputs.use_prerelease }}" == "true" ]; then | |
| echo "Would exit prerelease mode after publishing" | |
| fi | |
| echo "" | |
| echo "Current git status:" | |
| git status |