-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8549978
commit e8936ae
Showing
10 changed files
with
1,130 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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": [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
name: Changeset | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
create-release-pr: | ||
name: Create Changeset PR | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Use Node.js | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: 18 | ||
|
||
- name: Install Dependencies | ||
run: yarn --frozen-lockfile | ||
- name: Create Release Pull Request | ||
uses: changesets/action@v1 | ||
with: | ||
# Calls out to `changeset version`, but also runs prettier | ||
version: yarn release | ||
title: Version Packages - plugins | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
name: Node.js CI | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
build: | ||
env: | ||
NODE_OPTIONS: --max-old-space-size=4096 | ||
|
||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: '0' | ||
|
||
- name: Use Node.js | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: 18 | ||
|
||
- run: yarn install --frozen-lockfile | ||
- run: yarn lint:all | ||
- run: yarn tsc | ||
- run: yarn test:all | ||
- run: yarn build:all |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
name: Publish Build | ||
|
||
on: | ||
workflow_dispatch: | ||
push: | ||
branches: [main] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
outputs: | ||
needs_release: ${{ steps.release_check.outputs.needs_release }} | ||
|
||
env: | ||
CI: true | ||
NODE_OPTIONS: --max-old-space-size=4096 | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
|
||
- name: Set up Node.js | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: 18 | ||
|
||
- run: yarn install --frozen-lockfile | ||
|
||
- name: Fetch previous commit for release check | ||
run: git fetch origin '${{ github.event.before }}' | ||
|
||
- name: Check if release | ||
id: release_check | ||
run: node scripts/check-if-release.js | ||
env: | ||
COMMIT_SHA_BEFORE: '${{ github.event.before }}' | ||
|
||
- name: build type declarations | ||
run: yarn tsc | ||
|
||
- name: build packages | ||
run: yarn build | ||
|
||
# A separate release build that is only run for commits that are the result of merging the "Version Packages" PR | ||
# We can't re-use the output from the above step, but we'll have a guaranteed node_modules cache and | ||
# only run the build steps that are necessary for publishing | ||
release: | ||
needs: build | ||
|
||
if: needs.build.outputs.needs_release == 'true' | ||
|
||
runs-on: ubuntu-latest | ||
|
||
env: | ||
CI: 'true' | ||
NODE_OPTIONS: --max-old-space-size=4096 | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Set up Node.js | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: 18 | ||
|
||
- run: yarn install --frozen-lockfile | ||
|
||
- run: yarn tsc | ||
|
||
- run: yarn build:all | ||
|
||
- name: 'Login to npmjs npm repo .npmrc' | ||
shell: bash | ||
run: | | ||
echo "//registry.npmjs.org/:_authToken=${{secrets.NPM_AUTH_TOKEN}}" >> .npmrc | ||
echo "always-auth = true" >> .npmrc | ||
# Publishes current version of packages that are not already present in the registry. | ||
- name: Run publish | ||
run: | | ||
git config --global user.email "[email protected]" | ||
git config --global user.name "humanitec" | ||
lerna publish from-package --yes --no-verify-access | ||
# Creates the next available tag with format "release-<year>-<month>-<day>[.<n>]" | ||
- name: Create a release tag | ||
id: create_tag | ||
run: node scripts/create-release-tag.js | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
# Convert the newly created tag into a release with changelog information | ||
- name: Create release on GitHub | ||
run: node scripts/create-github-release.js ${{ steps.create_tag.outputs.tag_name }} 1 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
#!/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' | ||
|
||
const { execFile: execFileCb } = require('child_process'); | ||
const { resolve: resolvePath } = require('path'); | ||
const { promises: fs } = require('fs'); | ||
const { promisify } = require('util'); | ||
const { EOL } = require('os'); | ||
|
||
const parentRef = process.env.COMMIT_SHA_BEFORE || 'HEAD^'; | ||
|
||
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'); | ||
} | ||
|
||
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); | ||
}); |
Oops, something went wrong.