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

Update CLI and deployment #37

Merged
merged 12 commits into from
Jan 23, 2024
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
66 changes: 32 additions & 34 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ on:
concurrency: ${{ github.workflow }}-${{ github.ref }}

jobs:
tag:
name: New release
deploy:
name: Deploy
needs: [details]
runs-on: ubuntu-latest
if: ${{ fromJson(needs.details.outputs.result).shouldDeploy }}
Expand All @@ -30,7 +30,7 @@ jobs:
uses: AButler/[email protected]
with:
# e.g. dist/plugin-name-1.0.0.zip
files: "dist/${{ fromJson(needs.details.outputs.result).name }}-${{ fromJson(needs.details.outputs.result).version }}.zip"
files: "dist/${{ fromJson(needs.details.outputs.result).relativeDir }}-${{ fromJson(needs.details.outputs.result).version }}.zip"
repo-token: ${{ secrets.GITHUB_TOKEN }}

- name: Deploy to WordPress.org
Expand All @@ -41,19 +41,15 @@ jobs:
env:
SLUG: ${{ fromJson(needs.details.outputs.result).name }}
VERSION: ${{ fromJson(needs.details.outputs.result).version }}
BUILD_DIR: "dist/${{ fromJson(needs.details.outputs.result).name }}"
ASSETS_DIR: "${{ fromJson(needs.details.outputs.result).path }}/.wordpress-org"
SVN_USERNAME: ${{ secrets.SVN_USERNAME }}test
SVN_PASSWORD: ${{ secrets.SVN_PASSWORD }}test

- name: Copy README.md to dist
run: |
cp ${{ fromJson(needs.details.outputs.result).path }}/README.md dist/${{ fromJson(needs.details.outputs.result).name }}/README.md
BUILD_DIR: "dist/${{ fromJson(needs.details.outputs.result).relativeDir }}"
ASSETS_DIR: "${{ fromJson(needs.details.outputs.result).relativeDir }}/.wordpress-org"
SVN_USERNAME: ${{ secrets.SVN_USERNAME || 'test' }}
SVN_PASSWORD: ${{ secrets.SVN_PASSWORD || 'test' }}

- name: Deploy to repo
uses: manzoorwanijk/action-deploy-to-repo@v3
with:
src_dir: dist/${{ fromJson(needs.details.outputs.result).name }}
src_dir: dist/${{ fromJson(needs.details.outputs.result).relativeDir }}
target_repo: ${{ github.repository_owner }}/${{ fromJson(needs.details.outputs.result).name }}
target_dir: "."
target_branch: main
Expand All @@ -67,7 +63,21 @@ jobs:
outputs:
result: ${{ steps.details.outputs.result }}
steps:
- name: Get release details
- name: Checkout
uses: actions/checkout@v4

- name: Setup Environment
uses: ./actions/setup
with:
lockfile: pnpm-hashed.lock
enable-wireit-cache: true

- name: List projects
id: projects
run: |
echo "result=$(pnpm wpdev project-info --all)" >> $GITHUB_OUTPUT

- name: Get details
uses: actions/github-script@v7
id: details
with:
Expand All @@ -77,34 +87,22 @@ jobs:
const result = '${{ github.event.release.tag_name }}'.match(tagRegex);

if (!result) {
throw new Error('Invalid tag name: ${{ github.event.release.tag_name }}');
console.warn('Invalid tag name: "${{ github.event.release.tag_name }}"');

return { shouldDeploy: false };
}

const { name, version } = result.groups;

const plugins = [
'wptelegram',
'wptelegram-comments',
'wptelegram-login',
'wptelegram-widget',
];

const themes = [];

const toDeploy = [...plugins, ...themes];

const belongsTo = plugins.includes(name)
? 'plugins'
: themes.includes(name)
? 'themes'
: '';
const projects = ${{ steps.projects.outputs.result }};

const path = [belongsTo, name].filter(Boolean).join('/');
const project = projects.find(project => project.name === name);

const shouldDeploy = toDeploy.includes(name);
const shouldDeploy = Boolean(project);

return { name, version, path, shouldDeploy };
// User the version from the tag to ensure we're deploying the correct version
return { ...project, name, version, shouldDeploy };

- name: Print details
run: |
echo "Package details: ${{ steps.details.outputs.result }}"
echo "Details: ${{ steps.details.outputs.result }}"
6 changes: 0 additions & 6 deletions actions/setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,26 @@ description: "This action checks out the commit, sets up Node, pnpm, PHP, WP CLI
author: "wpsocio"
inputs:
cache-key:
required: false
description: "Cache busting key. If this changes, the cache will be busted."
default: "1"

node-version:
required: false
description: "The version of Node to use."
default: "lts/*"

php-version:
required: false
description: "The version of PHP to use."
default: "8"

pnpm-version:
required: false
description: "The version of pnpm to use."
default: "latest"

lockfile:
required: false
description: "The lockfile to use."
default: "pnpm-lock.yaml"

enable-wireit-cache:
required: false
description: "Enable Wireit cache."
default: "false"

Expand Down
3 changes: 3 additions & 0 deletions plugins/wpdev.base.project.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ export const getBundleConfig = ({ slug, key, version, textDomain }) => {
],
},
],
updateChangelog: {
readmeTxtFile: 'src/readme.txt',
},
generatePot: {
source: 'src',
textDomain,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,6 @@ For rules, see the pinned message. No spam please.
* Minor fixes

= 1.0.0 =
* Initial Release
* Initial Release

[See full changelog](https://github.com/wpsocio/wptelegram-comments/blob/main/CHANGELOG.md)
Original file line number Diff line number Diff line change
Expand Up @@ -174,4 +174,4 @@ Follow the instructions given on the settings page. You need to send `/setdomain
= 1.10.0 =
- Added support for Telegram Web App data authorization

== Upgrade Notice ==
[See full changelog](https://github.com/wpsocio/wptelegram-login/blob/main/CHANGELOG.md)
Original file line number Diff line number Diff line change
Expand Up @@ -235,4 +235,4 @@ Legacy Widget does not show the old messages. you need to post something new int
- Refreshed and improved the UI
- Improved names for hooks and shortcodes

== Upgrade Notice ==
[See full changelog](https://github.com/wpsocio/wptelegram-widget/blob/main/CHANGELOG.md)
Original file line number Diff line number Diff line change
Expand Up @@ -259,3 +259,5 @@ Yes, all you need to do is to setup **Private Notifications** module and use the
- Removed support for Markdown formatting in favour of better HTML formatting
- Fixed the image not being sent "After the text" when "Send files by URL" is disabled
- Fixed the issue of messages not being sent when the markup is not valid

[See full changelog](https://github.com/wpsocio/wptelegram/blob/main/CHANGELOG.md)
2 changes: 1 addition & 1 deletion pnpm-hashed.lock
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0380af5cd2a85662ece79600ffb61f58d0f415c9
f1b3f5ae40b67e51ebb53015bc016524ceb695e0
13 changes: 7 additions & 6 deletions pnpm-workspace.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
packages:
- 'packages/js/*'
- '!packages/js/shared'
- 'packages/js/shared/*'
- 'packages/php/*' # Just for running PHP tests via pnpm
- 'plugins/*'
- 'tools/*'
- "packages/js/*"
- "!packages/js/shared"
- "packages/js/shared/*"
- "packages/php/*" # Just for running PHP tests via pnpm
- "plugins/*"
# - "premium/plugins/*"
- "tools/*"
15 changes: 10 additions & 5 deletions tools/wpdev/src/base-commands/WithProjects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,14 @@ export abstract class WithProjects<
all: Flags.boolean({
description: 'Target all projects in monorepo.',
}),
'from-release': Flags.string({
'from-changeset': Flags.boolean({
description: 'Target projects in monorepo from changesets.',
dependsOn: ['changeset-json'],
}),
'changeset-json': Flags.file({
description:
'Target projects in monorepo that are to be released next. Pass the {filePath} given to `changset status --output={filePath}`',
'Path to the changeset status JSON file. Pass the {filePath} given to `changset status --output={filePath}`',
default: '',
}),
};

Expand Down Expand Up @@ -93,11 +98,11 @@ export abstract class WithProjects<
this.args = args as TArgs<T>;

if (this.cliConfig.operationMode === 'wp-monorepo') {
if (flags['from-release']) {
if (this.flags['from-changeset']) {
this.projects = this.wpMonorepo.getProjectsToRelease(
flags['from-release'],
this.flags['changeset-json'],
);
} else if (flags.all) {
} else if (this.flags.all) {
this.projects = this.wpMonorepo.getManagedProjects();
} else if (argv.length) {
this.projects = this.wpMonorepo.getProjectsByName(
Expand Down
76 changes: 49 additions & 27 deletions tools/wpdev/src/commands/bundle.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import fs from 'node:fs';
import path from 'node:path';
import { Flags } from '@oclif/core';
import chalk from 'chalk';
import { Listr, ListrTask } from 'listr2';
import { WithProjects } from '../base-commands/WithProjects.js';
import { updateChangelog } from '../utils/changelog.js';
import {
generatePotFile,
makeMoFiles,
potToPhp,
updatePoFiles,
} from '../utils/i18n.js';
import { copyDir, getDistIgnorePattern, zipDir } from '../utils/misc.js';
import { copyFiles, getDistIgnorePattern, zipDir } from '../utils/misc.js';
import {
getNextVersion,
getProjectConfig,
Expand All @@ -29,7 +31,8 @@ export default class Bundle extends WithProjects<typeof Bundle> {
static flags = {
'out-dir': Flags.string({
char: 'd',
description: 'Path to the output directory. Defaults to "dist/{slug}".',
description: 'Path to the output directory. Defaults to "dist".',
default: 'dist',
}),
'update-source-files': Flags.boolean({
char: 'u',
Expand Down Expand Up @@ -87,8 +90,6 @@ export default class Bundle extends WithProjects<typeof Bundle> {
...WithProjects.args,
};

protected destPlaceholder = '{slug}';

public async run(): Promise<void> {
const tasks = new Listr([], {
concurrent: true,
Expand Down Expand Up @@ -121,18 +122,14 @@ export default class Bundle extends WithProjects<typeof Bundle> {
}
}

getOutputDir() {
if (this.flags['out-dir']) {
return this.projects.size === 1
? this.flags['out-dir']
: path.join(this.flags['out-dir'], this.destPlaceholder);
}
getOutputDir(project: WPProject) {
const baseOutDir = this.flags['out-dir'] || 'dist';

return `dist/${this.destPlaceholder}`;
}
if (this.cliConfig.operationMode !== 'wp-monorepo') {
return baseOutDir;
}

parseOutputDir(outDir: string, slug: string) {
return outDir.replace(this.destPlaceholder, slug);
return path.join(baseOutDir, project.relativeDir);
}

getVersion(project: WPProject, task: TaskWrapper) {
Expand Down Expand Up @@ -170,7 +167,12 @@ export default class Bundle extends WithProjects<typeof Bundle> {

const { projectInfo, bundle } = await getProjectConfig(project, version);

const outDir = this.parseOutputDir(this.getOutputDir(), projectInfo.slug);
const outDir = this.getOutputDir(project);

// Clean up output directory
if (fs.existsSync(outDir)) {
fs.rmSync(outDir, { recursive: true });
}

const canChangeSourceFiles = this.flags['update-source-files'];

Expand Down Expand Up @@ -210,18 +212,38 @@ export default class Bundle extends WithProjects<typeof Bundle> {
}

const {
sourceDir,
destDir,
relativeSource,
files,
ignore = getDistIgnorePattern(project.dir),
} = bundle.tasks.copyFilesBefore;

return await copyDir(
path.join(project.dir, sourceDir),
this.parseOutputDir(destDir, projectInfo.slug),
{ ignore },
return await copyFiles(
path.join(project.dir, relativeSource),
{ files, ignore },
outDir,
);
},
},
{
title: 'Update changelog',
task: async (_, task) => {
if (
!bundle.tasks.updateChangelog ||
!this.flags['changeset-json']
) {
return task.skip();
}

const { readmeTxtFile } = bundle.tasks.updateChangelog;

return updateChangelog({
changesetJsonFile: this.flags['changeset-json'],
readmeTxtFile: path.join(project.dir, readmeTxtFile),
packageName: project.packageJson.name,
version,
});
},
},
{
title: 'Update requirements',
task: async (_, task) => {
Expand Down Expand Up @@ -346,15 +368,15 @@ export default class Bundle extends WithProjects<typeof Bundle> {
}

const {
sourceDir,
destDir,
relativeSource,
files,
ignore = getDistIgnorePattern(project.dir),
} = bundle.tasks.copyFilesAfter;

return await copyDir(
path.join(project.dir, sourceDir),
this.parseOutputDir(destDir, projectInfo.slug),
{ ignore },
return await copyFiles(
path.join(project.dir, relativeSource),
{ files, ignore },
outDir,
);
},
},
Expand Down
Loading