Skip to content

Commit

Permalink
feat: multiline packages (#27)
Browse files Browse the repository at this point in the history
Enable multiline packages using comma separated
  • Loading branch information
helciofranco authored Mar 20, 2024
1 parent 6be7065 commit 8c1170f
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 37 deletions.
4 changes: 3 additions & 1 deletion update-sdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ A github action to update the SDK packages.
@fuels
@fuels/react
@fuels/connectors
# Other way to use it
# fuels,@fuels/react,@fuels/connectors
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
```
Expand All @@ -25,7 +27,7 @@ A github action to update the SDK packages.
| ------------ | ---------------------------------------------------------- | -------------------------- |
| repository | Github Repository | `${{ github.repository }}` |
| branch | The branch that will be used to create the PR | `main` |
| packages | Packages to update (multiline input) | '' |
| packages | Packages to update (multiline input or comma separated) | '' |
| npm-tag | NPM tag (e.g. latest or next) | `latest` |

### Outputs
Expand Down
63 changes: 32 additions & 31 deletions update-sdk/dist/index.js

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion update-sdk/src/Github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ export class Github {
private repository: string
) {}

async getUpdatedPackages() {
async status() {
const { stdout } = await $`git status --porcelain=v1`;
return stdout;
}

async checkoutBranch(branchName: string) {
await $`git fetch`;
await $`git checkout ${branchName}`;
}

Expand Down
7 changes: 6 additions & 1 deletion update-sdk/src/PackageJson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ import { exec } from 'node:child_process';
import { promisify } from 'node:util';

export class PackageJson {
static async updateDependencies(version: string,packages: string[]) {
static getUpdatedPackages(status: string) {
const list = status.split('\n').filter((line) => line.includes('package.json'))
return list.filter((x) => x !== '').map((pkg) => pkg.trim());
}

static async updateDependencies(version: string, packages: string[]) {
const list = packages.map((pkg) => `"${pkg}@${version}"`).join(' ');

console.log(c.white(`📟 Running pnpm update for packages\n`));
Expand Down
6 changes: 4 additions & 2 deletions update-sdk/src/ReleaseBot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,16 @@ export class ReleaseBot {

await PackageJson.updateDependencies(npmTag, this.packages);

const updatedPackages = await this.git.getUpdatedPackages();
const gitStatus = await this.git.status();
const updatedPackages = PackageJson.getUpdatedPackages(gitStatus);

if (!updatedPackages.length) {
console.log(c.green('✅ No updated packages found'));
return;
}

console.log(c.green('⌛️ List of updated:'));
for (const updatedPackage of updatedPackages.split('\n')) {
for (const updatedPackage of updatedPackages) {
console.log(c.green(`📦 ${updatedPackage}`));
}

Expand Down
5 changes: 4 additions & 1 deletion update-sdk/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ async function main() {
const repository = core.getInput('repository');
const branch = core.getInput('branch');
const npmTag = core.getInput('npm-tag');
const packages = core.getMultilineInput('packages');

const inlinePackages = core.getInput('packages');
const isMultiline = inlinePackages.includes('\n');
const packages = isMultiline ? core.getMultilineInput('packages') : inlinePackages.split(',');

const bot = new ReleaseBot(repository, branch, npmTag, packages);
await bot.release();
Expand Down

0 comments on commit 8c1170f

Please sign in to comment.