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
8 changes: 8 additions & 0 deletions .changeset/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Changesets

Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works
with multi-package repos, or single-package repos to help you version and publish your code. You can
find the full documentation for it [in our repository](https://github.com/changesets/changesets)

We have a quick list of common questions to get you started engaging with this project in
[our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md)
11 changes: 11 additions & 0 deletions .changeset/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"$schema": "https://unpkg.com/@changesets/[email protected]/schema.json",
"changelog": "@changesets/cli/changelog",
"commit": false,
"fixed": [],
"linked": [],
"access": "restricted",
"baseBranch": "main",
"updateInternalDependencies": "patch",
"ignore": []
}
3 changes: 3 additions & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
* @hoangndst @Yangyang96

/plugins/scaffolder-backend-module-kusion @hoangndst
54 changes: 54 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: PR CI

on:
pull_request:
branches:
- main
push:
branches:
- main

jobs:
build:
runs-on: ubuntu-latest

env:
CI: true
NODE_OPTIONS: --max-old-space-size=4096

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-node@v4
with:
node-version: 20.x
cache: 'yarn'
- name: cache all node_modules
id: cache-modules
uses: actions/cache@v4 # v4
with:
path: '**/node_modules'
key: ${{ runner.os }}-node_modules-${{ hashFiles('yarn.lock', '**/package.json') }}
- name: find location of global yarn cache
id: yarn-cache
if: steps.cache-modules.outputs.cache-hit != 'true'
run: echo "dir=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT
- name: cache global yarn cache
uses: actions/cache@v4 # v4
if: steps.cache-modules.outputs.cache-hit != 'true'
with:
path: ${{ steps.yarn-cache.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: install dependencies
run: yarn install --immutable
- name: lint
run: yarn lint
- name: tsc
run: yarn tsc
- name: test
run: yarn test:all
- name: build
run: yarn build:all
85 changes: 85 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
name: Release Plugins

on:
push:
branches:
- main
workflow_dispatch:

jobs:
changesets-pr:
name: Update Version Packages PR
runs-on: ubuntu-latest
outputs:
needs_release: ${{ steps.release_check.outputs.needs_release }}
steps:
- name: Checkout
uses: actions/checkout@1d96c772d19495a3b5c517cd2bc0cb401ea0529f # v4

- name: Set up Node
uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4
with:
node-version: 20
registry-url: https://registry.npmjs.org/ # Needed for auth

- name: Fetch previous commit for check
run: git fetch origin '${{ github.event.before }}'

- name: Check if release
id: release_check
run: |
yarn install
node scripts/ci/check-if-release.js
working-directory: ./
env:
COMMIT_SHA_BEFORE: '${{ github.event.before }}'

- name: Update Version Packages PR
uses: backstage/changesets-action@291bfc1f76d1dcfbf967f5810dc0423592eae09a # v2.3.1
with:
title: Version Packages
version: yarn changeset version
skipRootChangelogUpdate: true
env:
GITHUB_TOKEN: ${{ secrets.KUSIONSTACK_BOT_TOKEN }}

release:
name: Release
runs-on: ubuntu-latest
needs: changesets-pr
if: needs.changesets-pr.outputs.needs_release == 'true'
env:
CI: true
NODE_OPTIONS: --max-old-space-size=4096

steps:
- name: Checkout
uses: actions/checkout@1d96c772d19495a3b5c517cd2bc0cb401ea0529f # v4

- name: Set up Node
uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4
with:
node-version: 20
registry-url: https://registry.npmjs.org/ # Needed for auth

- name: Install root dependencies
run: yarn install --immutable

- name: Compile TypeScript
run: yarn tsc

- name: Build all packages
run: yarn build:all

- name: publish
run: |
yarn config set -H 'npmAuthToken' "${{secrets.NPM_TOKEN}}"
yarn workspaces foreach -W -v --no-private npm publish --access public --tolerate-republish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Create tag
working-directory: ${{ github.workspace }}/scripts/ci
run: node create-tag.js
env:
GITHUB_TOKEN: ${{ secrets.KUSIONSTACK_BOT_TOKEN }}
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
"devDependencies": {
"@backstage/cli": "^0.29.0",
"@backstage/e2e-test-utils": "^0.1.1",
"@changesets/cli": "^2.29.4",
"@octokit/rest": "^21.1.1",
"@playwright/test": "^1.32.3",
"@spotify/prettier-config": "^12.0.0",
"node-gyp": "^10.0.0",
Expand Down
137 changes: 137 additions & 0 deletions scripts/ci/check-if-release.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
#!/usr/bin/env node
/* eslint-disable @backstage/no-undeclared-imports */
/*
* Copyright 2020 The Backstage Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

// This script is used to determine whether a particular commit has changes
// that should lead to a release. It is run as part of the main master build
// to determine whether the release flow should be run as well.
//
// It has the following output which can be used later in GitHub actions:
//
// needs_release = 'true' | 'false'

import { execFile as execFileCb } from 'child_process';
import { promises as fs } from 'fs';
import { promisify } from 'util';
import { resolve as resolvePath } from 'path';
import { EOL } from 'os';

import * as url from 'url';

const __dirname = url.fileURLToPath(new URL('.', import.meta.url));

const parentRef = process.env.COMMIT_SHA_BEFORE || 'HEAD^';
const targetBranch = process.env.TARGET_BRANCH || 'main';

const execFile = promisify(execFileCb);

async function runPlain(cmd, ...args) {
try {
const { stdout } = await execFile(cmd, args, { shell: true });
return stdout.trim();
} catch (error) {
if (error.stderr) {
process.stderr.write(error.stderr);
}
if (!error.code) {
throw error;
}
throw new Error(
`Command '${[cmd, ...args].join(' ')}' failed with code ${error.code}`,
);
}
}

async function main() {
process.cwd(resolvePath(__dirname));

if (!process.env.GITHUB_OUTPUT) {
throw new Error('GITHUB_OUTPUT environment variable not set');
}

// Ensure we have fetched the targetBranch
await runPlain('git', 'fetch', 'origin', targetBranch);

const diff = await runPlain(
'git',
'diff',
'--name-only',
parentRef,
"'*/package.json'", // Git treats this as what would usually be **/package.json
);

const packageList = diff
.split('\n')
.filter(path => path.match(/^(packages|plugins)\/[^/]+\/package\.json$/));

const packageVersions = await Promise.all(
packageList.map(async path => {
let name;
let newVersion;
let oldVersion;

try {
const data = JSON.parse(
await runPlain('git', 'show', `${parentRef}:${path}`),
);
name = data.name;
oldVersion = data.version;
} catch {
oldVersion = '<none>';
}

try {
const data = JSON.parse(await fs.readFile(path, 'utf8'));
name = data.name;
newVersion = data.version;
} catch (error) {
if (error.code === 'ENOENT') {
newVersion = '<none>';
}
}

return { name, oldVersion, newVersion };
}),
);

const newVersions = packageVersions.filter(
({ oldVersion, newVersion }) =>
oldVersion !== newVersion &&
oldVersion !== '<none>' &&
newVersion !== '<none>',
);

if (newVersions.length === 0) {
console.log('No package version bumps detected, no release needed');
await fs.appendFile(process.env.GITHUB_OUTPUT, `needs_release=false${EOL}`);
return;
}

console.log('Package version bumps detected, a new release is needed');
const maxLength = Math.max(...newVersions.map(_ => _.name.length));
for (const { name, oldVersion, newVersion } of newVersions) {
console.log(
` ${name.padEnd(maxLength, ' ')} ${oldVersion} to ${newVersion}`,
);
}
await fs.appendFile(process.env.GITHUB_OUTPUT, `needs_release=true${EOL}`);
}

main().catch(error => {
console.error(error.stack);
process.exit(1);
});
Loading