-
Notifications
You must be signed in to change notification settings - Fork 14
Improve build for packaging, add release workflow in CI #212
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
base: main
Are you sure you want to change the base?
Changes from all commits
92b46a8
9fc5bbe
98b7a32
ae9e311
4a9885b
d707d28
d113802
c004dd8
6de7a17
787f91b
865aa11
579ef4d
7f64555
f2067a8
f6c7c5c
d46ffaf
f71f616
9f9be1e
60b5b3a
67c95ff
9982d95
5cb6300
810e5d0
fd96741
90f8762
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| name: Update version on new release branch | ||
|
|
||
| on: | ||
| create: | ||
|
|
||
| permissions: | ||
| contents: write | ||
| pull-requests: write | ||
|
|
||
| jobs: | ||
| update_version: | ||
| if: github.ref_type == 'branch' && startsWith(github.ref, 'refs/heads/release-v') | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v5 | ||
|
|
||
| - name: Extract current version | ||
| run: | | ||
| CURRENT_VERSION=$(node -p "require('./contracts/package.json').version") | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm wondering if nodejs is available in the runner?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it is supported in the runner but I will add this part to be safe: |
||
| echo "CURRENT_VERSION=$CURRENT_VERSION" >> "$GITHUB_ENV" | ||
| - name: Extract new version number | ||
| run: echo "NEW_VERSION=${GITHUB_REF#refs/heads/release-v}" >> "$GITHUB_ENV" | ||
|
|
||
| - name: Replace version in files | ||
| run: | | ||
| echo "Current version: $CURRENT_VERSION" | ||
| echo "New version: $NEW_VERSION" | ||
| # Update package.json version field manually | ||
| cd contracts | ||
| node -e " | ||
| const fs = require('fs'); | ||
| const pkg = require('./package.json'); | ||
| pkg.version = '$NEW_VERSION'; | ||
| fs.writeFileSync('./package.json', JSON.stringify(pkg, null, 2) + '\n'); | ||
| console.log('Updated package.json to version $NEW_VERSION'); | ||
| " | ||
| # Update yarn.lock to reflect the new version | ||
| yarn install | ||
| cd .. | ||
| # Escape special characters for sed | ||
| ESCAPED_CURRENT=$(printf '%s' "$CURRENT_VERSION" | sed -e 's/[\/&]/\\&/g') | ||
| ESCAPED_NEW=$(printf '%s' "$NEW_VERSION" | sed -e 's/[\/&]/\\&/g') | ||
| # Replace version in contracts/src/ | ||
| find ./contracts/src/ -type d -name '.*' -prune -o \ | ||
| -type f -exec sed -i "s#$ESCAPED_CURRENT#$ESCAPED_NEW#g" {} + | ||
| # Replace version in docs/, excluding package-lock.json | ||
| find ./docs/ -type d -name '.*' -prune -o \ | ||
| -type f ! -name 'package-lock.json' -exec sed -i "s#$ESCAPED_CURRENT#$ESCAPED_NEW#g" {} + | ||
| - name: Auto-commit changes | ||
| uses: stefanzweifel/git-auto-commit-action@778341af668090896ca464160c2def5d1d1a3eb0 #v6.0.1 | ||
| with: | ||
| commit_message: Bump version to ${{ env.NEW_VERSION }} | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| name: Publish Package on Release | ||
|
|
||
| on: | ||
| release: | ||
| types: [published] | ||
|
|
||
| jobs: | ||
| publish: | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| contents: read | ||
| id-token: write | ||
|
|
||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v5 | ||
|
|
||
| - name: Setup Environment | ||
| uses: ./.github/actions/setup | ||
|
|
||
| - name: Build contracts | ||
| run: turbo build --filter=!'docs' | ||
|
|
||
| - name: Validate version consistency | ||
| run: | | ||
| RELEASE_VERSION=${GITHUB_REF#refs/tags/v} | ||
| PACKAGE_VERSION=$(node -p "require('./contracts/package.json').version") | ||
| if [ "$RELEASE_VERSION" != "$PACKAGE_VERSION" ]; then | ||
| echo "❌ Version mismatch: Release $RELEASE_VERSION vs Package $PACKAGE_VERSION" | ||
| exit 1 | ||
| fi | ||
| echo "✅ Version consistency validated: $RELEASE_VERSION" | ||
| - name: Setup npm registry | ||
| uses: actions/setup-node@v4 | ||
| with: | ||
| registry-url: 'https://registry.npmjs.org' | ||
|
|
||
| - name: Pack tarball | ||
| id: pack | ||
| run: | | ||
| cd contracts/dist | ||
| TARBALL=$(npm pack | tail -1) | ||
| echo "tarball_name=$TARBALL" >> $GITHUB_OUTPUT | ||
| echo "tarball=$(pwd)/$TARBALL" >> $GITHUB_OUTPUT | ||
| # Determine dist-tag based on semver prerelease | ||
| PACKAGE_VERSION=$(node -p "require('./package.json').version") | ||
| if [[ "$PACKAGE_VERSION" =~ -.*$ ]]; then | ||
| # Has prerelease suffix (anything after -) | ||
| if [[ "$PACKAGE_VERSION" =~ -(alpha|beta|rc) ]]; then | ||
| echo "tag=beta" >> $GITHUB_OUTPUT | ||
| else | ||
| echo "tag=next" >> $GITHUB_OUTPUT | ||
| fi | ||
| else | ||
| # Stable release | ||
| echo "tag=latest" >> $GITHUB_OUTPUT | ||
| fi | ||
| - name: Verify tarball integrity | ||
| run: | | ||
| echo "=== Verifying tarball contents ===" | ||
| PACKAGE_NAME=$(tar xfO "${{ steps.pack.outputs.tarball }}" package/package.json | jq -r .name) | ||
| PACKAGE_VERSION=$(tar xfO "${{ steps.pack.outputs.tarball }}" package/package.json | jq -r .version) | ||
| PRIVATE_FIELD=$(tar xfO "${{ steps.pack.outputs.tarball }}" package/package.json | jq -r '.private // "not found"') | ||
| echo "📦 Package: $PACKAGE_NAME@$PACKAGE_VERSION" | ||
| echo "🏷️ Tag: ${{ steps.pack.outputs.tag }}" | ||
| echo "🔒 Private field: $PRIVATE_FIELD" | ||
| # Ensure no private field | ||
| if [ "$PRIVATE_FIELD" = "true" ]; then | ||
| echo "❌ Tarball contains private: true - cannot publish" | ||
| exit 1 | ||
| fi | ||
| - name: Publish to npm | ||
| run: | | ||
| # Create .npmrc with auth token | ||
| echo "//registry.npmjs.org/:_authToken=\${NPM_TOKEN}" > .npmrc | ||
| # Publish the tarball with appropriate tag | ||
| npm publish "${{ steps.pack.outputs.tarball }}" --tag "${{ steps.pack.outputs.tag }}" --access public | ||
| env: | ||
| NPM_TOKEN: ${{ secrets.NPM_TOKEN }} | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We will need to switch this over to Trusted Publishing later. I am tracking that on my side. |
||
| NPM_CONFIG_PROVENANCE: true | ||
|
|
||
| - name: Log success | ||
| run: | | ||
| PACKAGE_NAME=$(tar xfO "${{ steps.pack.outputs.tarball }}" package/package.json | jq -r .name) | ||
| PACKAGE_VERSION=$(tar xfO "${{ steps.pack.outputs.tarball }}" package/package.json | jq -r .version) | ||
| echo "✅ Successfully published $PACKAGE_NAME@$PACKAGE_VERSION to npm with tag ${{ steps.pack.outputs.tag }}" | ||
| echo "📦 Install with: npm install $PACKAGE_NAME@${{ steps.pack.outputs.tag }}" | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's better to extract these out to Actions variables instead of hardcoding, can be a separate improvement PR later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also would like to see some verification for the downloaded file, like a SHA256 hash or something.