Skip to content

Commit

Permalink
Tools: Make server build more configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
laurent22 committed Feb 23, 2022
1 parent cc69cab commit 4649011
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 16 deletions.
6 changes: 4 additions & 2 deletions .github/scripts/run_ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ echo "GITHUB_REF=$GITHUB_REF"
echo "RUNNER_OS=$RUNNER_OS"
echo "GIT_TAG_NAME=$GIT_TAG_NAME"
echo "BUILD_SEQUENCIAL=$BUILD_SEQUENCIAL"
echo "SERVER_REPOSITORY=$SERVER_REPOSITORY"
echo "SERVER_TAG_PREFIX=$SERVER_TAG_PREFIX"

echo "IS_CONTINUOUS_INTEGRATION=$IS_CONTINUOUS_INTEGRATION"
echo "IS_PULL_REQUEST=$IS_PULL_REQUEST"
Expand Down Expand Up @@ -169,10 +171,10 @@ cd "$ROOT_DIR/packages/app-desktop"
if [[ $GIT_TAG_NAME = v* ]]; then
echo "Step: Building and publishing desktop application..."
USE_HARD_LINKS=false yarn run dist
elif [[ $GIT_TAG_NAME = server-v* ]] && [[ $IS_LINUX = 1 ]]; then
elif [[ $IS_LINUX = 1 ]] && [[ $GIT_TAG_NAME = $SERVER_TAG_PREFIX-* ]]; then
echo "Step: Building Docker Image..."
cd "$ROOT_DIR"
yarn run buildServerDocker --tag-name $GIT_TAG_NAME --push-images
yarn run buildServerDocker --tag-name $GIT_TAG_NAME --push-images --repository $SERVER_REPOSITORY
else
echo "Step: Building but *not* publishing desktop application..."
USE_HARD_LINKS=false yarn run dist --publish=never
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/github-actions-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ jobs:
env:
IS_CONTINUOUS_INTEGRATION: 1
BUILD_SEQUENCIAL: 1
SERVER_REPOSITORY: joplin/server
SERVER_TAG_PREFIX: server
run: |
yarn install && cd packages/app-desktop && yarn run dist --publish=never
Expand Down Expand Up @@ -138,5 +140,5 @@ jobs:
BUILD_SEQUENCIAL: 1
run: |
yarn install
yarn run buildServerDocker --tag-name server-v0.0.0
yarn run buildServerDocker --tag-name server-v0.0.0 --repository joplin/server
2 changes: 0 additions & 2 deletions packages/tools/buildServerDocker.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ describe('buildServerDocker', function() {
const actual = getVersionFromTag(tagName, isPreRelease);
expect(actual).toBe(expected);
}

expect(() => getVersionFromTag('app-cli-v1.0.0', false)).toThrow();
});

test('should check if it is a pre-release', async () => {
Expand Down
18 changes: 13 additions & 5 deletions packages/tools/buildServerDocker.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import { execCommand2, rootDir } from './tool-utils';
import * as moment from 'moment';

interface Argv {
dryRun?: boolean;
pushImages?: boolean;
repository?: string;
tagName?: string;
}

export function getVersionFromTag(tagName: string, isPreRelease: boolean): string {
if (tagName.indexOf('server-') !== 0) throw new Error(`Invalid tag: ${tagName}`);
const s = tagName.split('-');
const suffix = isPreRelease ? '-beta' : '';
return s[1].substr(1) + suffix;
Expand All @@ -16,11 +22,13 @@ export function getIsPreRelease(_tagName: string): boolean {
}

async function main() {
const argv = require('yargs').argv;
const argv = require('yargs').argv as Argv;
if (!argv.tagName) throw new Error('--tag-name not provided');
if (!argv.repository) throw new Error('--repository not provided');

const dryRun = !!argv.dryRun;
const pushImages = !!argv.pushImages;
const repository = argv.repository;
const tagName = argv.tagName;
const isPreRelease = getIsPreRelease(tagName);
const imageVersion = getVersionFromTag(tagName, isPreRelease);
Expand Down Expand Up @@ -48,7 +56,7 @@ async function main() {
console.info('isPreRelease:', isPreRelease);
console.info('Docker tags:', dockerTags.join(', '));

const dockerCommand = `docker build --progress=plain -t "joplin/server:${imageVersion}" ${buildArgs} -f Dockerfile.server .`;
const dockerCommand = `docker build --progress=plain -t "${repository}:${imageVersion}" ${buildArgs} -f Dockerfile.server .`;
if (dryRun) {
console.info(dockerCommand);
return;
Expand All @@ -57,8 +65,8 @@ async function main() {
await execCommand2(dockerCommand);

for (const tag of dockerTags) {
await execCommand2(`docker tag "joplin/server:${imageVersion}" "joplin/server:${tag}"`);
if (pushImages) await execCommand2(`docker push joplin/server:${tag}`);
await execCommand2(`docker tag "${repository}:${imageVersion}" "${repository}:${tag}"`);
if (pushImages) await execCommand2(`docker push ${repository}:${tag}`);
}
}

Expand Down
7 changes: 5 additions & 2 deletions packages/tools/git-changelog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ enum Platform {
Desktop = 'desktop',
Clipper = 'clipper',
Server = 'server',
Cloud = 'cloud',
Cli = 'cli',
PluginGenerator = 'plugin-generator',
PluginRepoCli = 'plugin-repo-cli',
Expand Down Expand Up @@ -84,6 +85,7 @@ function platformFromTag(tagName: string): Platform {
if (tagName.indexOf('clipper') === 0) return Platform.Clipper;
if (tagName.indexOf('cli') === 0) return Platform.Cli;
if (tagName.indexOf('server') === 0) return Platform.Server;
if (tagName.indexOf('cloud') === 0) return Platform.Cloud;
if (tagName.indexOf('plugin-generator') === 0) return Platform.PluginGenerator;
if (tagName.indexOf('plugin-repo-cli') === 0) return Platform.PluginRepoCli;
throw new Error(`Could not determine platform from tag: "${tagName}"`);
Expand Down Expand Up @@ -115,7 +117,7 @@ function filterLogs(logs: LogEntry[], platform: Platform) {
let addIt = false;

// "All" refers to desktop, CLI and mobile app. Clipper and Server are not included.
if (prefix.indexOf('all') >= 0 && (platform !== 'clipper' && platform !== 'server')) addIt = true;
if (prefix.indexOf('all') >= 0 && (platform !== 'clipper' && platform !== 'server' && platform !== 'cloud')) addIt = true;
if ((platform === 'android' || platform === 'ios') && prefix.indexOf('mobile') >= 0) addIt = true;
if (platform === 'android' && prefix.indexOf('android') >= 0) addIt = true;
if (platform === 'ios' && prefix.indexOf('ios') >= 0) addIt = true;
Expand All @@ -124,6 +126,7 @@ function filterLogs(logs: LogEntry[], platform: Platform) {
if (platform === 'cli' && prefix.indexOf('cli') >= 0) addIt = true;
if (platform === 'clipper' && prefix.indexOf('clipper') >= 0) addIt = true;
if (platform === 'server' && prefix.indexOf('server') >= 0) addIt = true;
if (platform === 'cloud' && prefix.indexOf('cloud') >= 0) addIt = true;

// Translation updates often comes in format "Translation: Update pt_PT.po"
// but that's not useful in a changelog especially since most people
Expand Down Expand Up @@ -155,7 +158,7 @@ function formatCommitMessage(commit: string, msg: string, author: Author, option
const isPlatformPrefix = (prefixString: string) => {
const prefix = prefixString.split(',').map(p => p.trim().toLowerCase());
for (const p of prefix) {
if (['android', 'mobile', 'ios', 'desktop', 'cli', 'clipper', 'all', 'api', 'plugins', 'server'].indexOf(p) >= 0) return true;
if (['android', 'mobile', 'ios', 'desktop', 'cli', 'clipper', 'all', 'api', 'plugins', 'server', 'cloud'].indexOf(p) >= 0) return true;
}
return false;
};
Expand Down
10 changes: 6 additions & 4 deletions packages/tools/tool-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ function commandToString(commandName: string, args: string[] = []) {
return output.join(' ');
}

async function insertChangelog(tag: string, changelogPath: string, changelog: string, isPrerelease: boolean) {
async function insertChangelog(tag: string, changelogPath: string, changelog: string, isPrerelease: boolean, repoTagUrl: string = '') {
repoTagUrl = repoTagUrl || 'https://github.com/laurent22/joplin/releases/tag';

const currentText = await fs.readFile(changelogPath, 'UTF-8');
const lines = currentText.split('\n');

Expand All @@ -60,7 +62,7 @@ async function insertChangelog(tag: string, changelogPath: string, changelog: st

const header = [
'##',
`[${tag}](https://github.com/laurent22/joplin/releases/tag/${tag})`,
`[${tag}](${repoTagUrl}/${tag})`,
];
if (isPrerelease) header.push('(Pre-release)');
header.push('-');
Expand Down Expand Up @@ -91,10 +93,10 @@ export function releaseFinalGitCommands(appName: string, newVersion: string, new
return finalCmds.join(' && ');
}

export async function completeReleaseWithChangelog(changelogPath: string, newVersion: string, newTag: string, appName: string, isPreRelease: boolean) {
export async function completeReleaseWithChangelog(changelogPath: string, newVersion: string, newTag: string, appName: string, isPreRelease: boolean, repoTagUrl = '') {
const changelog = (await execCommand2(`node ${rootDir}/packages/tools/git-changelog ${newTag} --publish-format full`, { })).trim();

const newChangelog = await insertChangelog(newTag, changelogPath, changelog, isPreRelease);
const newChangelog = await insertChangelog(newTag, changelogPath, changelog, isPreRelease, repoTagUrl);

await fs.writeFile(changelogPath, newChangelog);

Expand Down

0 comments on commit 4649011

Please sign in to comment.