Fix npm publish by re-enabling corepack #56
Workflow file for this run
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: Release Package | |
| on: | |
| push: | |
| branches: [main] | |
| pull_request: | |
| branches: [main] | |
| jobs: | |
| check-version: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| version-changed: ${{ steps.check.outputs.changed }} | |
| current-version: ${{ steps.check.outputs.current-version }} | |
| previous-version: ${{ steps.check.outputs.previous-version }} | |
| is-prerelease: ${{ steps.check.outputs.is-prerelease }} | |
| npm-tag: ${{ steps.check.outputs.npm-tag }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Check if version needs publishing | |
| id: check | |
| run: | | |
| current_version=$(jq -r '.version' package.json) | |
| package_name=$(jq -r '.name' package.json) | |
| echo "current-version=$current_version" >> $GITHUB_OUTPUT | |
| # Check if this version exists on npm | |
| if npm view "${package_name}@${current_version}" version 2>/dev/null; then | |
| echo "Version $current_version already published to npm" | |
| echo "changed=false" >> $GITHUB_OUTPUT | |
| previous_version="$current_version" | |
| else | |
| echo "Version $current_version not found on npm, will publish" | |
| echo "changed=true" >> $GITHUB_OUTPUT | |
| # Get the latest published version for reference | |
| previous_version=$(npm view "${package_name}" version 2>/dev/null || echo "none") | |
| fi | |
| echo "previous-version=$previous_version" >> $GITHUB_OUTPUT | |
| # Check if this is a pre-release version | |
| if [[ "$current_version" =~ -(alpha|beta|rc|dev|pre|canary|next) ]]; then | |
| echo "is-prerelease=true" >> $GITHUB_OUTPUT | |
| tag="$(echo "$current_version" | cut -d'-' -f2)" | |
| echo "npm-tag=$tag" >> $GITHUB_OUTPUT | |
| echo "Detected pre-release version with tag: $tag" | |
| else | |
| echo "is-prerelease=false" >> $GITHUB_OUTPUT | |
| echo "npm-tag=latest" >> $GITHUB_OUTPUT | |
| echo "Detected stable release version" | |
| fi | |
| build-and-publish: | |
| runs-on: ubuntu-latest | |
| needs: check-version | |
| if: needs.check-version.outputs.version-changed == 'true' | |
| permissions: | |
| contents: read | |
| id-token: write | |
| outputs: | |
| published-version: ${{ needs.check-version.outputs.current-version }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| submodules: recursive | |
| # Setup .npmrc file to publish to npm | |
| - uses: actions/setup-node@v4 | |
| with: | |
| node-version-file: '.tool-versions' | |
| registry-url: 'https://registry.npmjs.org' | |
| - name: enable corepack | |
| run: | | |
| corepack enable | |
| corepack prepare yarn@4.10.3 --activate | |
| - name: cache yarn dependencies | |
| uses: actions/cache@v4 | |
| with: | |
| path: ~/.yarn/cache | |
| key: ${{ runner.os }}-yarn-${{ hashfiles('**/yarn.lock') }} | |
| restore-keys: | | |
| ${{ runner.os }}-yarn- | |
| - run: yarn install --immutable | |
| - run: yarn build | |
| - name: Prepare package for publishing | |
| run: yarn readme | |
| - name: Upgrade npm for OIDC trusted publishing | |
| run: npm install -g npm@latest | |
| - name: Publish to npm | |
| env: | |
| # Skip prepack script since we already ran yarn readme | |
| NPM_CONFIG_IGNORE_SCRIPTS: true | |
| run: | | |
| # Use npm CLI directly - requires npm >= 11.5.1 for OIDC trusted publishing | |
| # Yarn 4.10.3 OIDC support appears broken despite all env vars being set correctly | |
| if [ "${{ needs.check-version.outputs.is-prerelease }}" == "true" ]; then | |
| npm publish --provenance --access public --tag ${{ needs.check-version.outputs.npm-tag }} | |
| else | |
| npm publish --provenance --access public | |
| fi | |
| create-release: | |
| runs-on: ubuntu-latest | |
| needs: [check-version, build-and-publish] | |
| if: needs.build-and-publish.result == 'success' && needs.check-version.outputs.is-prerelease == | |
| 'false' | |
| permissions: | |
| contents: write | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: enable corepack | |
| run: | | |
| corepack enable | |
| corepack prepare yarn@4.9.2 --activate | |
| - name: Create Release | |
| uses: actions/create-release@v1 | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| with: | |
| tag_name: v${{ needs.check-version.outputs.current-version }} | |
| release_name: v${{ needs.check-version.outputs.current-version }} | |
| body: | | |
| See [CHANGELOG](https://github.com/ReforgeHQ/cli/blob/main/CHANGELOG.md) for details. | |
| Published to npm: [@reforge-com/cli@${{ needs.check-version.outputs.current-version }}](https://www.npmjs.com/package/@reforge-com/cli/v/${{ needs.check-version.outputs.current-version }}) | |
| draft: false | |
| prerelease: false |