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

prepare for new version of release-script #337

Merged
merged 9 commits into from
Jul 23, 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
96 changes: 3 additions & 93 deletions .github/workflows/create-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,109 +33,19 @@ jobs:
node-version: ${{ matrix.node }}

- name: Install dependencies
run: npm ci --ignore-scripts
run: npm ci

- name: Test
run: npm test

- name: Determine the version bump
id: version
uses: actions/github-script@v7
- name: Prepare release
env:
VERSION_BUMP: ${{ inputs.versionBump }}
with:
result-encoding: string
script: |
const semver = require('semver');

const prevVersion = require(`${process.env.GITHUB_WORKSPACE}/package.json`).version;

const parsed = semver.parse(prevVersion);

// Figure out the next version
const version = `${semver.inc(parsed, process.env.VERSION_BUMP)}`;

return version;

- name: Prepare io-package.json
env:
VERSION: ${{ steps.version.outputs.result }}
uses: actions/github-script@v7
with:
script: |
const semver = require('semver');
const fs = require('fs-extra');

const MAX_NEWS = 20;
const path = `${process.env.GITHUB_WORKSPACE}/io-package.json`;

const ioPack = require(path);

let news = ioPack.common.news;

const prevNewsVersion = Object.keys(news)[0];

// add new news as first entry
news = { [process.env.VERSION]: Object.values(news)[0], ...news };

const isPatch = semver.satisfies(process.env.VERSION, `~${prevNewsVersion}`);

if (isPatch) {
delete news[prevNewsVersion];
}

// if too much news, remove them
while (Object.keys(news).length > MAX_NEWS) {
const newsVersions = Object.keys(news);
delete news[newsVersions[newsVersions.length - 1]];
}

ioPack.common.news = news;
ioPack.common.version = process.env.VERSION;

fs.writeFileSync(path, JSON.stringify(ioPack, null, 2));


- name: Prepare changelog
env:
VERSION: ${{ steps.version.outputs.result }}
uses: actions/github-script@v7
with:
script: |
const fs = require('fs-extra');

const WIP_MARKER = '__WORK IN PROGRESS__';

const TEMP_PLACEHOLDER = '**TEMP_PLACEHOLDER_GH_ACTION**';
const changelog = fs
.readFileSync(`${process.env.GITHUB_WORKSPACE}/README.md`, { encoding: 'utf-8' })
.replace(WIP_MARKER, TEMP_PLACEHOLDER);

if (!changelog.includes(WIP_MARKER)) {
throw new Error(`${WIP_MARKER} is missing in changelog`);
}

const dateStr = new Date().toISOString().split('T')[0];

const versionDateStr = `${process.env.VERSION} (${dateStr})`;

fs.writeFileSync(
`${process.env.GITHUB_WORKSPACE}/README.md`,
changelog.replace(WIP_MARKER, versionDateStr).replace(TEMP_PLACEHOLDER, WIP_MARKER),
{
encoding: 'utf-8'
}
);

- name: Bump version locally
env:
VERSION: ${{ steps.version.outputs.result }}
run: |
git config --global user.email "[email protected]"
git config --global user.name "Github Action"

git add .
git commit -m "v${VERSION}"
npm run release -- ${VERSION_BUMP}

- name: Create Pull Request
id: cpr
Expand Down
Loading