Skip to content
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

Do not run the npm publish action if package version was published #33

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
- run: deno publish
working-directory: ${{ matrix.workspace }}
npm:
if: fromJSON(needs.generate-matrix.outputs.exists)
if: ${{ fromJSON(needs.generate-matrix.outputs.exists)}}
name: Publish ${{ matrix.name }}@${{matrix.version}} to NPM
runs-on: ubuntu-latest

Expand All @@ -71,6 +71,7 @@ jobs:
- run: deno run -A www/tasks/build-npm.ts ${{matrix.workspace}}

- run: npm publish --access=public --tag=latest
if: ${{ matrix.npmVersionUnpublished }}
working-directory: ${{matrix.workspace}}/build/npm
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
Expand Down
19 changes: 19 additions & 0 deletions www/hooks/use-npm-client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { createContext } from "effection";
import { Client } from "jsr:@yorganci/[email protected]";
import { call } from "effection";

const NPMClientContext = createContext("npm-client", new Client());

export function* isVersionPublished(name: string, versionOrTag = "latest") {
const client = yield* NPMClientContext;

try {
yield* call(() => client.getPackageManifest(name, versionOrTag));
return true;
} catch (error) {
if (error instanceof Deno.errors.NotFound) {
return false;
}
throw error;
}
}
3 changes: 3 additions & 0 deletions www/tasks/publish-matrix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { call, each, main } from "effection";
import { usePackages } from "../hooks/use-packages.ts";
import { DenoJson } from "../hooks/use-package.tsx";
import { x } from "../../tinyexec/mod.ts";
import { isVersionPublished } from "../hooks/use-npm-client.ts";

await main(function* () {
let packages = yield* usePackages();
Expand Down Expand Up @@ -33,6 +34,8 @@ await main(function* () {
tagname,
name: pkg.name,
version: pkg.version,
npmVersionUnpublished:
!(yield* isVersionPublished(pkg.name, pkg.version)),
});
}
}
Expand Down
Loading