Merge pull request #9134 from backstage/mob/release-manifest

github-actions: Add assemble release workflow
This commit is contained in:
Johan Haals
2022-01-25 13:34:16 +01:00
committed by GitHub
2 changed files with 113 additions and 0 deletions
@@ -0,0 +1,34 @@
name: Sync Release Manifest
on:
workflow_dispatch:
inputs:
version:
description: 'Version number'
required: true
jobs:
create-new-version:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
ref: ${{ github.event.inputs.version }}
- name: Install dependencies
run: yarn install
- name: Checkout versions
uses: actions/checkout@v2
with:
repository: backstage/versions
path: versions
token: ${{ secrets.GH_SERVICE_ACCOUNT_TOKEN }}
- name: Configure Git
run: |
git config --global user.email noreply@backstage.io
git config --global user.name 'Github versions workflow'
- name: Create release
run: |
node scripts/assemble-manifest.js ${{ github.event.inputs.version }}
cd versions
git add .
git commit -am "${{ github.event.inputs.version }}"
git push
+79
View File
@@ -0,0 +1,79 @@
#!/usr/bin/env node
/* eslint-disable import/no-extraneous-dependencies */
/*
* Copyright 2022 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.
*/
const semver = require('semver');
const fs = require('fs-extra');
const { getPackages } = require('@manypkg/get-packages');
const path = require('path');
async function main() {
const [script, version] = process.argv.slice(1);
if (!version) {
throw new Error(`Argument must be ${script} <version>`);
}
if (!semver.valid(version)) {
throw new Error(`version '${version}' must be a valid semver`);
}
const manifestDir = path.resolve('versions', 'v1', 'releases', version);
if (await fs.pathExists(manifestDir)) {
throw new Error(
`Release manifest path for version ${version} already exists`,
);
}
console.log(`Assembling packages for backstage release ${version}`);
const { packages } = await getPackages(path.resolve('.'));
const versions = packages
.filter(
p =>
(p.packageJson.name.startsWith('@backstage/') ||
p.packageJson.name.startsWith('@techdocs/')) &&
p.packageJson.private === false,
)
.map(p => {
return { name: p.packageJson.name, version: p.packageJson.version };
});
await fs.ensureDir(manifestDir);
await fs.writeJSON(
path.resolve(manifestDir, 'manifest.json'),
{ releaseVersion: version, packages: versions },
{ spaces: 2 },
);
const tag = version.includes('next') ? 'next' : 'main';
const tagPath = path.resolve('versions', 'v1', 'tags', tag);
if (await fs.pathExists(tagPath)) {
const currentTag = await fs.readJSON(
path.resolve(tagPath, 'manifest.json'),
);
if (semver.gt(currentTag.releaseVersion, version)) {
console.log(
`Skipping update of ${tagPath} since current current ${tag} version is ${currentTag.releaseVersion}`,
);
process.exit(1);
}
}
await fs.remove(tagPath);
await fs.ensureSymlink(path.join('..', 'releases', version), tagPath);
}
main().catch(error => {
console.error(error.stack);
process.exit(1);
});