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

new: Support monorepo based tag names. #4

Merged
merged 2 commits into from
Jan 21, 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
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# 0.3.0

- Updated to support monorepo based tags.
- Added `tagged-project` output.

# 0.2.3

- Removed "Changelog" title from release body.
Expand All @@ -12,7 +17,7 @@

# 0.2.0

- Added `built`, `changelog-entry`, and `tag-version` outputs.
- Added `built`, `changelog-entry`, and `tagged-version` outputs.
- Will attempt to extract a changelog.
- Refer to our readme for an updated GitHub workflow example.

Expand Down
4 changes: 3 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,7 @@ outputs:
description: 'Whether the plugins have been built or not.'
changelog-entry:
description: 'The changelog entry, if it exists.'
tag-version:
tagged-project:
description: 'The project affected by a Git tag, if applicable.'
tagged-version:
description: 'The extracted version from a Git tag, if applicable.'
49 changes: 43 additions & 6 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,54 @@ function getRoot(): string {
return process.env.GITHUB_WORKSPACE!;
}

let TAG: string | null = null;
let PLUGIN: string | null = null;
let PLUGIN_VERSION: string | null = null;

function detectVersion() {
function detectVersionAndProject() {
const ref = process.env.GITHUB_REF;

if (ref && ref.startsWith('refs/tags/')) {
let version = ref.replace('refs/tags/', '');
const tag = ref.replace('refs/tags/', '');
let project = '';
let version = '';

core.info(`Detected tag ${tag}`);
TAG = tag;

// project-v1.0.0
if (project.includes('-')) {
const lastIndex = project.lastIndexOf('-');

project = project.slice(0, lastIndex);
version = project.slice(lastIndex + 1);
}

// project@v1.0.0
else if (project.includes('@')) {
[project, version] = project.split('@');
}

// v1.0.0
else {
version = tag;
}

if (version.startsWith('v') || version.startsWith('V')) {
version = version.slice(1);
}

core.setOutput('tag-version', version);

core.info(`Detected tagged version ${version}`);
core.setOutput('tagged-version', version);

PLUGIN_VERSION = version;

if (project) {
core.info(`Detected tagged project ${project}`);
core.setOutput('tagged-project', project);

PLUGIN = project;
}
}
}

Expand Down Expand Up @@ -133,6 +164,11 @@ async function findBuildablePackages() {
return;
}

if (PLUGIN && pkg.name !== PLUGIN) {
core.info(`Skipping ${pkg.name}, not associated to tag ${TAG}`);
return;
}

core.info(`Found ${pkg.name}, loading manifest ${pkg.manifest_path}, checking targets`);

const manifest = TOML.parse(fs.readFileSync(pkg.manifest_path, 'utf8')) as Manifest;
Expand Down Expand Up @@ -243,10 +279,11 @@ async function extractChangelog() {
async function run() {
core.setOutput('built', 'false');
core.setOutput('changelog-entry', '');
core.setOutput('tag-version', '');
core.setOutput('tagged-project', '');
core.setOutput('tagged-version', '');

try {
detectVersion();
detectVersionAndProject();

const builds = await findBuildablePackages();

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@
},
"devDependencies": {
"@types/changelog-parser": "^2.8.4",
"@types/node": "^20.11.0",
"@types/node": "^20.11.5",
"@vercel/ncc": "^0.38.1",
"eslint": "^8.56.0",
"eslint-config-moon": "^2.0.14",
"prettier": "^3.1.1",
"prettier": "^3.2.4",
"prettier-config-moon": "^1.1.2",
"ts-node": "^10.9.2",
"tsconfig-moon": "^1.3.0",
Expand Down
22 changes: 11 additions & 11 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.