Skip to content
Merged
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 package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"packages": [
"utils",
"publish-pr-preview",
"synchronize-npm-tags"
"synchronize-npm-tags",
"synchronize-with-npm"
]
},
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion publish-pr-preview/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:

### Specifying Install Script

The action will by default run either `yarn install --frozen-lockfile` or `npm ci`, but if there are additional steps required before your packages can be published, you can specify your own install script that runs at the root of your repository;
The action will by default run either `yarn install --frozen-lockfile` or `npm ci`, but if there are additional steps required before your packages can be published, you can specify your own install script that runs at the root of your repository:

```yaml
- uses: thefrontside/publish-pr-preview@main
Expand Down
1 change: 1 addition & 0 deletions publish-pr-preview/src/checkPrerequisites.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export function* checkPrerequisites(payload: PullRequestPayload): Operation<Prer
let buffer: string[] = yield gitDiff.stdout.lines().toArray();
let { code: gitDiffExitCode } = yield gitDiff.join();
if (gitDiffExitCode !== 0) {
// TODO remove period at the end for consistency
return { isValid: false, reason: "The base commit could not be found. Configure the checkout action in your workflow with the correct settings." };
} else {
return { isValid: true, payload: buffer, branch: headBranch };
Expand Down
3 changes: 1 addition & 2 deletions synchronize-npm-tags/src/findPublicPackages.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import fs from "fs";
import { listAllPkgJsons } from "@frontside/actions-utils";
import { logIterable } from "./logIterable";
import { listAllPkgJsons, logIterable } from "@frontside/actions-utils";

export function findPublicPackages(): string[] {
let privatePackages: string[] = [];
Expand Down
15 changes: 0 additions & 15 deletions synchronize-npm-tags/src/logIterable.ts

This file was deleted.

3 changes: 1 addition & 2 deletions synchronize-npm-tags/src/removeTags.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { all, Operation } from "effection";
import { exec, ProcessResult } from "@effection/process";
import { PackageTags } from ".";
import { colors } from "@frontside/actions-utils";
import { logIterable } from "./logIterable";
import { colors, logIterable } from "@frontside/actions-utils";

export function* removeTags({
allPackageTags,
Expand Down
7 changes: 0 additions & 7 deletions synchronize-with-npm/Dockerfile

This file was deleted.

65 changes: 41 additions & 24 deletions synchronize-with-npm/README.md
Original file line number Diff line number Diff line change
@@ -1,35 +1,52 @@
# Synchronize with NPM
This action will review all the available packages and see if the user intends on publishing any of them by evaluating if the current package version exists.
# Synchronize With NPM

:star: NEW :star: deprecation feature: See below in `Deprecate Packages` section below.

## Requirements
- Pass in `secrets.GITHUB_TOKEN` into `GITHUB_TOKEN`.
- :exclamation: Must be `GITHUB_TOKEN` and not a personal access token of a bot. :exclamation:
- Pass in `NPM_TOKEN`.
- Optional: Specify `IGNORE` argument for directory of packages you don't want published.
- Optional: `NPM_PUBLISH` argument is available if you want to run a different command. `npm publish` will run as default.
- :warning: However, if you provide this argument, it will run that script to publish for every package (if you're running this action on a monorepo). If you would need to run a custom command once for the repository and not each individual packages, use `BEFORE_ALL` (see below).
- Optional: Passing in an argument for `BEFORE_ALL` will run that command after `npm install` or `yarn install` but before the action starts navigating into the different packages in the monorepo to start the publishign process.
The `synchronize-with-npm` action will publish your packages after running `npm view` for each package in your monorepo or repository to check to see if the version of your packages have been published yet. This action can also deprecating packages on NPM. See below for details.

## Usage

```yaml
on:
push:
branches:
- main

jobs:
job_name:
name: Job Name
runs-on: ubuntu-16.04
release:
name: Publish Releases
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Syncrhonize with NPM
uses: thefrontside/actions/synchronize-with-npm@master
- uses: actions/checkout@v2
- uses: actions/step-node@v2
with:
BEFORE_ALL: npm run prepack-after-install
NPM_PUBLISH: npm run my-script
IGNORE: packages/to/ignore
registry-url: https://registry.npmjs.org
## https://github.com/actions/setup-node/blob/main/docs/advanced-usage.md#publish-to-npmjs-and-gpr-with-npm
- uses: thefrontside/synchronize-with-npm@main
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
```

## Deprecate Packages
When a package in a monorepo needs to be deprecated, this action will take care of that. All you need to do is add `"deprecate": "deprecation message"` inside the `package.json` of the package you wish to deprecate on NPM.
### Specifying Install Script

The action will by default run either `yarn install --frozen-lockfile` or `npm ci`, but if there are additional steps required before your packages can be published, you can specify your own install script that runs at the root of your repository:

```yaml
- uses: thefrontside/synchronize-with-npm@main
with:
INSTALL_SCRIPT: yarn my_install_command
env:
NODE_AUTH_TOKEN: ...
GITHUB_TOKEN: ...
```

### Deprecating Packages

If you wish to deprecate any of your packages, you can simply update your `package.json` with a `deprecate` property and provide it with a deprecation message:

```json
{
"name": "package-to-deprecate",
"version": "1.0.0",
"deprecate": "This package has been deprecated"
}
```
11 changes: 11 additions & 0 deletions synchronize-with-npm/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: Synchronize with NPM
description: Publish Releases

inputs:
INSTALL_SCRIPT:
description: "If you need to specify your own install command"
required: false

runs:
using: "node12"
main: "dist/index.js"
1 change: 1 addition & 0 deletions synchronize-with-npm/dist/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {};
7 changes: 7 additions & 0 deletions synchronize-with-npm/dist/index.js

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions synchronize-with-npm/dist/src/checkIfPublished.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Operation } from "effection";
import { ToPublish } from "./listPackages";
export declare function checkIfPublished({ pkgsToPublish }: {
pkgsToPublish: ToPublish[];
}): Operation<ToPublish[]>;
5 changes: 5 additions & 0 deletions synchronize-with-npm/dist/src/deprecatePackages.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Operation } from "effection";
import { ToDeprecate } from "./listPackages";
export declare function deprecatePackages({ pkgsToDeprecate }: {
pkgsToDeprecate: ToDeprecate[];
}): Operation<string[]>;
18 changes: 18 additions & 0 deletions synchronize-with-npm/dist/src/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { GitHub } from "@actions/github/lib/utils";
import { WebhookPayload } from "@actions/github/lib/interfaces";
import * as Core from "@actions/core/lib/core";
import { Operation } from "effection";
export interface GithubActionsPayload extends WebhookPayload {
repository: WebhookPayload["repository"] & {
owner: {
login: string;
};
name: string;
};
}
export interface ActionPayload {
octokit: InstanceType<typeof GitHub>;
core: typeof Core;
payload: GithubActionsPayload;
}
export declare function run({ octokit, core, payload }: ActionPayload): Operation<void>;
15 changes: 15 additions & 0 deletions synchronize-with-npm/dist/src/listPackages.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export interface ToDeprecate {
name: string;
description: string;
}
export interface ToPublish {
name: string;
version: string;
path: string;
}
interface PackagesList {
pkgsToPublish: ToPublish[];
pkgsToDeprecate: ToDeprecate[];
}
export declare function listPackages(): PackagesList;
export {};
12 changes: 12 additions & 0 deletions synchronize-with-npm/dist/src/publishAndTag.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { GitHub } from "@actions/github/lib/utils";
import { Operation } from "effection";
import { ToPublish } from "./listPackages";
import { GithubActionsPayload } from ".";
interface Publish {
confirmedPkgsToPublish: ToPublish[];
installScript: string;
octokit: InstanceType<typeof GitHub>;
payload: GithubActionsPayload;
}
export declare function publishAndTag({ confirmedPkgsToPublish, installScript, octokit, payload, }: Publish): Operation<ToPublish[]>;
export {};
144 changes: 0 additions & 144 deletions synchronize-with-npm/entrypoint.sh

This file was deleted.

14 changes: 14 additions & 0 deletions synchronize-with-npm/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import * as core from "@actions/core";
import * as github from "@actions/github";
import fs from "fs";
import { main } from "effection";
import { run } from "./src";

const token = process.env.GITHUB_TOKEN || "";
const octokit = github.getOctokit(token);

const payload = JSON.parse(fs.readFileSync(`${process.env.GITHUB_EVENT_PATH}`, "utf-8"));

main(
run({ octokit, core, payload })
);
Loading