fix: same dir in the workflow #8
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 all CLIs & Deploy CF Workers | |
# Add permissions for writing contents (releases, tags, commits) and PRs | |
permissions: | |
contents: write | |
pull-requests: write | |
on: | |
pull_request: | |
branches: [main] | |
types: [opened, synchronize] | |
push: | |
branches: [main] | |
env: | |
WORKSPACES: create-db create-pg create-postgres | |
jobs: | |
# πΎ On PRs: bump package.json versions & CHANGELOGs via Changesets | |
version: | |
if: ${{ github.event_name == 'pull_request' }} | |
runs-on: ubuntu-latest | |
steps: | |
- name: ποΈ Checkout full & tags | |
# Updated to v4 for the latest features and security | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
persist-credentials: true | |
- name: π€ Disable Husky | |
run: echo "HUSKY=0" >> $GITHUB_ENV | |
- name: π¦ Setup pnpm | |
# Updated to v4 for the latest features and security | |
uses: pnpm/action-setup@v4 | |
with: | |
version: 8 | |
- name: π§ Install dependencies | |
# Using --frozen-lockfile is a best practice in CI to ensure reproducibility | |
run: pnpm install --frozen-lockfile | |
- name: π Version & changelogs via Changesets | |
uses: changesets/action@v1 | |
with: | |
# This command creates the version bump commit | |
version: "pnpm changeset version" | |
# Custom commit message for the version bump | |
commit: "chore(release): bump versions" | |
# Donβt create a GitHub release on a PR run | |
createGithubReleases: false | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
# π On merges to main: aggregate CHANGELOGs, tag & publish | |
publish: | |
if: ${{ github.event_name == 'push' }} | |
runs-on: ubuntu-latest | |
steps: | |
- name: ποΈ Checkout full & tags | |
# Updated to v4 | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
# Credentials are not needed for this job as it doesn't push commits | |
persist-credentials: false | |
- name: π€ Disable Husky | |
run: echo "HUSKY=0" >> $GITHUB_ENV | |
- name: π¦ Setup pnpm | |
# Updated to v4 | |
uses: pnpm/action-setup@v4 | |
with: | |
version: 8 | |
- name: π§ Install dependencies | |
run: pnpm install --frozen-lockfile | |
- name: π§ Install jq | |
# Combine update and install into a single layer | |
run: sudo apt-get update && sudo apt-get install -y jq | |
- name: π Copy README to child CLIs | |
# FIX: Added a condition to prevent copying a file to its own location | |
run: | | |
for pkg in $WORKSPACES; do | |
if [ "$pkg" != "create-db" ]; then | |
cp create-db/README.md "$pkg/README.md" | |
fi | |
done | |
- name: π Aggregate changelogs | |
id: aggregate | |
run: | | |
# Pull the new version out of package.json from the primary workspace | |
NEW_VERSION=$(jq -r '.version' create-db/package.json) | |
echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_ENV | |
# Header for the release body | |
echo "# Release v$NEW_VERSION" > AGGREGATED_CHANGELOG.md | |
echo "" >> AGGREGATED_CHANGELOG.md | |
for pkg in $WORKSPACES; do | |
echo "## \`$pkg\`" >> AGGREGATED_CHANGELOG.md | |
# IMPROVEMENT: Use a more robust awk command to extract changelog entries. | |
# This correctly handles cases where the version is the last one in the file. | |
awk -v ver="## $NEW_VERSION" ' | |
$0 ~ ver { found=1; next } | |
/^## / { found=0 } | |
found { print } | |
' "$pkg/CHANGELOG.md" >> AGGREGATED_CHANGELOG.md | |
echo "" >> AGGREGATED_CHANGELOG.md | |
done | |
- name: π© Create GitHub Release | |
uses: actions/create-release@v1 | |
with: | |
tag_name: v${{ env.NEW_VERSION }} | |
release_name: Release v${{ env.NEW_VERSION }} | |
body_path: AGGREGATED_CHANGELOG.md | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: π Configure npm auth | |
run: echo "//registry.npmjs.org/:_authToken=${{ secrets.CREATE_DB_TOKEN_NPM }}" > ~/.npmrc | |
- name: π Publish CLIs | |
run: pnpm -r --filter "{create-db,create-pg,create-postgres}" publish --access public | |
# β CF production deploys commented out β | |
# - name: βοΈ Deploy create-db-worker (production) | |
# uses: cloudflare/wrangler-action@v3 | |
# ... | |
- name: π§Ή Cleanup npm auth | |
if: ${{ always() }} | |
run: rm -f ~/.npmrc |