|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + |
| 8 | +concurrency: ${{ github.workflow }}-${{ github.ref }} |
| 9 | + |
| 10 | +jobs: |
| 11 | + release: |
| 12 | + name: Release |
| 13 | + runs-on: ubuntu-latest |
| 14 | + steps: |
| 15 | + - name: Checkout |
| 16 | + uses: actions/checkout@v4 |
| 17 | + with: |
| 18 | + fetch-depth: 0 |
| 19 | + |
| 20 | + - name: Setup pnpm |
| 21 | + uses: pnpm/action-setup@v4 |
| 22 | + with: |
| 23 | + version: 10.18.3 |
| 24 | + |
| 25 | + - name: Setup Node.js |
| 26 | + uses: actions/setup-node@v4 |
| 27 | + with: |
| 28 | + node-version: 20 |
| 29 | + cache: 'pnpm' |
| 30 | + |
| 31 | + - name: Install dependencies |
| 32 | + run: pnpm install --frozen-lockfile |
| 33 | + |
| 34 | + - name: Create Release Pull Request or Publish to npm |
| 35 | + id: changesets |
| 36 | + uses: changesets/action@v1 |
| 37 | + with: |
| 38 | + version: pnpm version-packages |
| 39 | + publish: pnpm release |
| 40 | + commit: 'chore: version packages' |
| 41 | + title: 'chore: version packages' |
| 42 | + env: |
| 43 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 44 | + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 45 | + |
| 46 | + - name: Create GitHub Releases |
| 47 | + if: steps.changesets.outputs.published == 'true' |
| 48 | + env: |
| 49 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 50 | + run: | |
| 51 | + # Parse published packages and create releases for each |
| 52 | + echo '${{ steps.changesets.outputs.publishedPackages }}' | jq -c '.[]' | while read -r package; do |
| 53 | + name=$(echo "$package" | jq -r '.name') |
| 54 | + version=$(echo "$package" | jq -r '.version') |
| 55 | +
|
| 56 | + # Determine package directory |
| 57 | + if [[ "$name" == "@plotday/sdk" ]]; then |
| 58 | + pkg_dir="sdk" |
| 59 | + elif [[ "$name" == @plotday/tool-* ]]; then |
| 60 | + tool_name="${name#@plotday/tool-}" |
| 61 | + pkg_dir="tools/$tool_name" |
| 62 | + else |
| 63 | + echo "Unknown package: $name" |
| 64 | + continue |
| 65 | + fi |
| 66 | +
|
| 67 | + # Create tag name (e.g., sdk@0.9.1 or tool-google-calendar@0.1.0) |
| 68 | + tag_name="${pkg_dir//\//@}@${version}" |
| 69 | +
|
| 70 | + # Extract changelog entry for this version |
| 71 | + changelog_file="$pkg_dir/CHANGELOG.md" |
| 72 | + if [ -f "$changelog_file" ]; then |
| 73 | + # Extract the section for this version from CHANGELOG |
| 74 | + release_notes=$(awk "/## ${version}/,/## [0-9]/" "$changelog_file" | sed '1d;$d' | sed '/^$/d') |
| 75 | +
|
| 76 | + if [ -z "$release_notes" ]; then |
| 77 | + release_notes="Release ${name}@${version}" |
| 78 | + fi |
| 79 | + else |
| 80 | + release_notes="Release ${name}@${version}" |
| 81 | + fi |
| 82 | +
|
| 83 | + # Create GitHub release |
| 84 | + echo "Creating release for $name@$version with tag $tag_name" |
| 85 | + gh release create "$tag_name" \ |
| 86 | + --title "${name}@${version}" \ |
| 87 | + --notes "$release_notes" \ |
| 88 | + --verify-tag || echo "Release creation failed for $tag_name, may already exist" |
| 89 | + done |
| 90 | +
|
| 91 | + - name: Summary |
| 92 | + if: steps.changesets.outputs.published == 'true' |
| 93 | + run: | |
| 94 | + echo "### 🚀 Published Packages" >> $GITHUB_STEP_SUMMARY |
| 95 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 96 | + echo "The following packages were published to npm:" >> $GITHUB_STEP_SUMMARY |
| 97 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 98 | + echo '${{ steps.changesets.outputs.publishedPackages }}' | jq -r '.[] | "- **\(.name)@\(.version)** ([GitHub Release](https://github.com/${{ github.repository }}/releases/tag/\(.name | gsub("@plotday/"; "") | gsub("/"; "@"))@\(.version)))"' >> $GITHUB_STEP_SUMMARY |
0 commit comments