Repository navigation
refactor: move the code into a Bun workspace #4
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
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 |
|---|---|---|
| @@ -1,29 +1,35 @@ | ||
| name: Release | ||
|
|
||
| # On every push to main: | ||
| # - release-please opens or updates a release PR. It reads the Conventional Commit | ||
| # messages (fix:, feat:, feat!:) since the last release, and bumps the version in | ||
| # package.json and adds the changes to CHANGELOG.md to match. | ||
| # - release-please opens or updates the CLI's release PR (release-please/cli-config.json). | ||
| # It reads the Conventional Commit messages (fix:, feat:, feat!:) since the last | ||
| # release, leaving out commits that only change packages/mcp: so a change to | ||
| # packages/core, which isn't published, or to the lockfile or the build releases the | ||
| # CLI too. It bumps the version in packages/cli/version.txt and package.json and adds | ||
| # the changes to packages/cli/CHANGELOG.md to match. | ||
| # - The binaries and the npm package of HEAD are built with a -dev version and kept as a | ||
| # workflow artifact, tinify-<version>. The Windows binary is checked on Windows, since | ||
| # the build runs on macOS; nothing is published unless that check passes. | ||
| # - Unless the push creates a release, that build replaces the unstable pre-release on | ||
| # - Unless the push creates a release, that build replaces the cli-main pre-release on | ||
| # GitHub. Unreleased builds never go to npm. | ||
| # Merging the release PR tags the release and creates the GitHub Release; the binaries are | ||
| # then attached to it and the npm package is published. | ||
| # Merging the release PR tags the release cli-v<version> and creates its GitHub Release as | ||
| # a draft. Once the binaries are attached it's published as the latest release, which the | ||
| # README's download links use, so they never reach a release without them. The npm package | ||
| # is published too. | ||
| # | ||
| # Run it by hand with a release's tag to build and publish that release again, for example | ||
| # after a failed upload or publish. What is already published is kept: only missing | ||
| # binaries are uploaded, replacing what a failed upload left behind, and SHA256SUMS is | ||
| # made from the binaries on the release. | ||
| # after a failed upload or publish. Pick that tag under "Use workflow from" too, so this | ||
| # file matches the release's files, which older releases lay out differently. What is | ||
| # already published is kept: only missing binaries are uploaded, replacing what a failed | ||
| # upload left behind, and SHA256SUMS is made from the binaries on the release. | ||
|
|
||
| on: | ||
| push: | ||
| branches: [main] | ||
| workflow_dispatch: | ||
| inputs: | ||
| tag: | ||
| description: Tag of an existing GitHub Release, e.g. v1.0.0 | ||
| description: Tag of an existing GitHub Release, e.g. cli-v1.1.0. Pick it under "Use workflow from" too. | ||
| required: true | ||
| type: string | ||
|
|
||
|
|
@@ -46,16 +52,18 @@ jobs: | |
| pull-requests: write | ||
| issues: write | ||
| outputs: | ||
| release_created: ${{ steps.release.outputs.release_created }} | ||
| tag_name: ${{ steps.release.outputs.tag_name }} | ||
| release_created: ${{ steps.cli.outputs.release_created }} | ||
| tag_name: ${{ steps.cli.outputs.tag_name }} | ||
| steps: | ||
| - uses: googleapis/release-please-action@45996ed1f6d02564a971a2fa1b5860e934307cf7 # v5.0.0 | ||
| id: release | ||
| id: cli | ||
| with: | ||
| # PRs opened with the default GITHUB_TOKEN don't trigger the CI workflow, so the | ||
| # release PR gets no checks. To fix that, add a RELEASE_PLEASE_TOKEN secret: a | ||
| # fine-grained token with contents and pull requests read/write on this repo. | ||
| token: ${{ secrets.RELEASE_PLEASE_TOKEN || github.token }} | ||
| config-file: release-please/cli-config.json | ||
| manifest-file: release-please/cli-manifest.json | ||
|
|
||
| build: | ||
| needs: release-please | ||
|
|
@@ -87,16 +95,16 @@ jobs: | |
| - name: Set the version | ||
| id: version | ||
| run: | | ||
| version=$(bun -p 'require("./package.json").version') | ||
| version=$(bun -p 'require("./packages/cli/package.json").version') | ||
| if [ "$RELEASE" = true ]; then | ||
| if [ "$TAG" != "v$version" ]; then | ||
| echo "::error::Tag $TAG doesn't match version $version in package.json" | ||
| if [ "$TAG" != "cli-v$version" ]; then | ||
| echo "::error::Tag $TAG doesn't match version $version in packages/cli/package.json" | ||
| exit 1 | ||
| fi | ||
| else | ||
| # Builds of HEAD can't be mistaken for the release they come after. | ||
| version="$version-dev+${GITHUB_SHA:0:7}" | ||
| npm pkg set version="$version" | ||
| (cd packages/cli && npm pkg set version="$version") | ||
| fi | ||
| echo "version=$version" >> "$GITHUB_OUTPUT" | ||
|
|
||
|
|
@@ -105,10 +113,10 @@ jobs: | |
| - name: Check the binary runs and reports the version | ||
| env: | ||
| VERSION: ${{ steps.version.outputs.version }} | ||
| run: test "$(./dist/tinify-darwin-arm64 --version)" = "$VERSION" | ||
| run: test "$(packages/cli/dist/tinify-darwin-arm64 --version)" = "$VERSION" | ||
|
|
||
| # The npm package is plain JavaScript for Node; check it runs on exactly the oldest | ||
| # Node that package.json's engines allows. | ||
| # Node that packages/cli/package.json's engines allows. | ||
| - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 | ||
| with: | ||
| node-version: 20.12.0 | ||
|
|
@@ -121,16 +129,16 @@ jobs: | |
| env: | ||
| VERSION: ${{ steps.version.outputs.version }} | ||
| run: | | ||
| npm install --global --prefix "$RUNNER_TEMP/npm-check" --no-audit --no-fund dist/npm/*.tgz | ||
| npm install --global --prefix "$RUNNER_TEMP/npm-check" --no-audit --no-fund packages/cli/dist/npm/*.tgz | ||
| test "$("$RUNNER_TEMP/npm-check/bin/tinify" --version)" = "$VERSION" | ||
|
|
||
| - uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 | ||
| with: | ||
| name: tinify-${{ steps.version.outputs.version }} | ||
| path: dist/ | ||
| path: packages/cli/dist/ | ||
| if-no-files-found: error | ||
| # It carries the build to the publish jobs below; the unstable release keeps the | ||
| # latest one. | ||
| # It carries the build to the publish jobs below; the cli-main pre-release keeps | ||
| # the latest one. | ||
| retention-days: 14 | ||
|
|
||
| check-windows: | ||
|
|
@@ -211,6 +219,18 @@ jobs: | |
| (cd published && sha256sum tinify-* > SHA256SUMS) | ||
| upload published/SHA256SUMS | ||
| fi | ||
| # release-please made the release a draft; with its binaries attached, it's | ||
| # published. A release published before, which a manual run only completes, stays | ||
| # as it is. The latest release, which the README's download links use, only moves | ||
| # forward: a manual run that publishes an older release's draft leaves it alone. | ||
| # The lookups are assigned first, so a failed one fails the job. | ||
| draft=$(gh release view "$TAG" --json isDraft --jq .isDraft --repo "$GITHUB_REPOSITORY") | ||
| if [ "$draft" = true ]; then | ||
| latest=$(gh release view --json tagName --jq .tagName --repo "$GITHUB_REPOSITORY") | ||
|
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. The publish step fails when no stable release exists. Line 229 reads the latest release with no tag argument. The header describes every draft as publishing "as the latest release." It does not describe a first stable release. The workflow has no behavior for the case where no latest release exists. Define the required behavior for that case. Either publish the first draft as latest, or require a published stable release before this step runs. Keep failing on other lookup errors. Document the chosen behavior in the workflow header.
|
||
| newest=$(printf '%s\n' "${latest##*v}" "${TAG##*v}" | sort -V | tail -n 1) | ||
| make_latest=$([ "$newest" = "${TAG##*v}" ] && echo true || echo false) | ||
| gh release edit "$TAG" --draft=false --latest="$make_latest" --repo "$GITHUB_REPOSITORY" | ||
| fi | ||
|
|
||
| npm: | ||
| # Listing check-windows in needs isn't enough: with !cancelled(), a job runs even | ||
|
|
@@ -246,10 +266,11 @@ jobs: | |
| npm publish "dist/npm/tinify-cli-$VERSION.tgz" | ||
| fi | ||
|
|
||
| # Every push to main that doesn't cut a release replaces the "unstable" pre-release with | ||
| # its build, so a fix can be tried before it's released. Unreleased builds never go to | ||
| # npm: a version published there can't be taken back. | ||
| unstable: | ||
| # Every push to main that doesn't cut a release replaces the "cli-main" pre-release with | ||
| # its build, so a fix can be tried before it's released. Each published package has a | ||
| # <name>-main of its own, so their builds don't replace each other's. Unreleased builds | ||
| # never go to npm: a version published there can't be taken back. | ||
| prerelease: | ||
| # Listing check-windows in needs isn't enough: with !cancelled(), a job runs even | ||
| # after a job it needs failed, so its result is checked too. | ||
| needs: [build, check-windows] | ||
|
|
@@ -263,7 +284,7 @@ jobs: | |
| name: tinify-${{ needs.build.outputs.version }} | ||
| path: dist | ||
|
|
||
| - name: Replace the unstable pre-release | ||
| - name: Replace the cli-main pre-release | ||
| env: | ||
| GH_TOKEN: ${{ github.token }} | ||
| GH_REPO: ${{ github.repository }} | ||
|
|
@@ -274,11 +295,12 @@ jobs: | |
| # "+" of the version in it, which GitHub would rewrite. | ||
| mv dist/npm/*.tgz dist/npm/tinify-cli.tgz | ||
| # There's none on the first run. | ||
| gh release delete unstable --cleanup-tag --yes || true | ||
| gh release delete cli-main --cleanup-tag --yes || true | ||
| notes="Unreleased build of $GITHUB_SHA on main, version $VERSION, for trying a fix before it's released. Not for production use: use the [latest release](https://github.com/$GITHUB_REPOSITORY/releases/latest) for that. | ||
|
|
||
| The macOS binaries aren't notarized, so macOS refuses to run one downloaded in a browser: \`xattr -d com.apple.quarantine tinify-darwin-arm64\` (or \`tinify-darwin-x64\` on an Intel Mac) lifts that. The npm package installs with \`npm install -g ./tinify-cli.tgz\`." | ||
| # gh publishes the release only once every file is uploaded. | ||
| gh release create unstable dist/tinify-* dist/SHA256SUMS dist/npm/tinify-cli.tgz \ | ||
| --prerelease --target "$GITHUB_SHA" --title "$VERSION" \ | ||
| # Titled like release-please's releases ("cli: v1.0.1"). | ||
| gh release create cli-main dist/tinify-* dist/SHA256SUMS dist/npm/tinify-cli.tgz \ | ||
| --prerelease --target "$GITHUB_SHA" --title "cli: $VERSION" \ | ||
| --notes "$notes" | ||
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.