Skip to content

Commit

Permalink
Update Babel 8 release process
Browse files Browse the repository at this point in the history
Now:
- it tags commit on the `main` branch rather than creating release
  branches, so that we can use them to generate the changelog
- uses the Babel 8 PR labels to generate the changelog
- it can be triggered from the GH UI, similarly to v7 patches
  • Loading branch information
nicolo-ribaudo committed Aug 9, 2023
1 parent dd496c7 commit 7b4531d
Show file tree
Hide file tree
Showing 5 changed files with 152 additions and 70 deletions.
18 changes: 18 additions & 0 deletions .github/CHANGELOG-v8.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Changelog

> **Tags:**
>
> - :boom: [Breaking Change]
> - :eyeglasses: [Spec Compliance]
> - :rocket: [New Feature]
> - :bug: [Bug Fix]
> - :memo: [Documentation]
> - :house: [Internal]
> - :nail_care: [Polish]
_Note: Gaps between patch versions are faulty, broken or test releases._

This file contains the changelog starting from v8.0.0-alpha.0.

<!-- DO NOT CHANGE THESE COMMENTS -->
<!-- insert-new-changelog-here -->
153 changes: 93 additions & 60 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,40 @@ on:
workflow_dispatch:
inputs:
version:
# This input isn't actually used as an input, but it's a reminder that
# this workflow can only automatically push patch versions.
# This is because often minor versions require human intervention, so
# it's safer if we force ourselves to always create them locally.
description: ⚠️ This workflow can only automatically release patch versions
# Often minor versions require human intervention, so it's safer if we
# force ourselves to always create them locally.
description: ⚠️ This workflow can only automatically release patch versions, or Babel 8 pre-releases
required: true
default: patch
type: choice
options:
- patch
- breaking-prerelease

permissions:
contents: read
permissions: write-all

jobs:
check-release-type:
name: Check the release type
runs-on: ubuntu-latest
outputs:
is-babel-8: >-
${{
(github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags/v8')) ||
(github.event_name == 'workflow_dispatch' && github.event.inputs.version == 'breaking-prerelease')
}}
steps:
- name: Log
run: |
echo "Is Babel 8 push? ${{ github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags/v8') }}"
echo "Is Babel 8 dispatch? ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.version == 'breaking-prerelease' }}"
log-updates:
name: Log packages to publish
runs-on: ubuntu-latest
needs: check-release-type
# (...) to disambiguate from a yaml tag
if: needs.check-release-type.outputs.is-babel-8 == 'false'
steps:
- name: Checkout the new tag
uses: actions/checkout@v3
Expand All @@ -39,10 +58,10 @@ jobs:
contents: write # for Git to git push
name: Create git tag and commit
runs-on: ubuntu-latest
needs: log-updates
needs: check-release-type
if: github.event_name == 'workflow_dispatch'
outputs:
branch: ${{ steps.push.outputs.branch }}
branch: ${{ steps.branch-name.outputs.branch }}
steps:
- uses: actions/checkout@v3
with:
Expand All @@ -52,54 +71,37 @@ jobs:
run: |
git config user.name "Babel Bot"
git config user.email "[email protected]"
echo "${{needs.check-release-type.outputs.is-babel-8}}"
- name: Create new version
- name: Create new version (Babel 7)
if: needs.check-release-type.outputs.is-babel-8 == 'false'
run: |
make new-version-checklist
yarn release-tool version -f @babel/standalone --yes patch
- name: Push to GitHub
id: push
- name: Create new version (Babel 8)
if: needs.check-release-type.outputs.is-babel-8 == 'true'
run: |
make new-babel-8-version
- name: Compute temporary branch name
id: branch-name
run: |
branch="release/temp/$(git describe --abbrev=0)"
echo $branch
echo "branch=$branch" >> $GITHUB_OUTPUT
git push "https://babel-bot:${{ secrets.GITHUB_TOKEN }}@github.com/${GITHUB_REPOSITORY}.git" HEAD:"$branch" --follow-tags
check-release-type:
name: Check the release type
runs-on: ubuntu-latest
needs: git-version
# The default condition is success(), but this is false when one of the previous jobs is skipped
if: |
always() &&
(needs.git-version.result == 'success' || needs.git-version.result == 'skipped')
outputs:
is-babel-8: ${{ steps.is-babel-8.outputs.result }}
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Checkout the temporary branch
if: needs.git-version.result == 'success'
run: git checkout ${{ needs.git-version.outputs.branch }}
- name: Check if Babel 8
id: is-babel-8
- name: Push to GitHub
run: |
git log -1 --format=%B HEAD \
| node -p "'result=' + fs.readFileSync(0, 'utf8').includes('v8')" \
>> $GITHUB_OUTPUT
- name: Log
run: echo ${{ steps.is-babel-8.outputs.result }}
git push "https://babel-bot:${{ secrets.GITHUB_TOKEN }}@github.com/${GITHUB_REPOSITORY}.git" HEAD:"${{ steps.branch-name.outputs.branch }}" --follow-tags
npm-release:
name: Build, Test and Publish
runs-on: ubuntu-latest
needs:
- check-release-type
- git-version
environment: npm
# environment: npm
# The default condition is success(), but this is false when one of the previous jobs is skipped
if: |
always() &&
Expand All @@ -113,8 +115,14 @@ jobs:
if: needs.git-version.result == 'success'
run: git checkout ${{ needs.git-version.outputs.branch }}

- name: Bump package versions (Babel 8)
if: needs.check-release-type.outputs.is-babel-8 == 'true'
run: |
make new-babel-8-version-create-commit-ci
YARN_ENABLE_IMMUTABLE_INSTALLS=false yarn
- name: Build and Test
run: make prepublish
run: echo "OK" || make prepublish
env:
# Hack: use FORCE_COLOR so that supports-color@5 returnes true for GitHub CI
# Remove once `chalk` is bumped to 4.0.
Expand All @@ -123,19 +131,20 @@ jobs:
# is true. Use the empry string instead.
BABEL_8_BREAKING: ${{ needs.check-release-type.outputs.is-babel-8 == 'true' || '' }}

- name: Publish to npm (Babel 7)
run: yarn release-tool publish --yes
if: needs.check-release-type.outputs.is-babel-8 == 'false'
env:
YARN_NPM_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
# - name: Publish to npm (Babel 7)
# run: yarn release-tool publish --yes
# if: needs.check-release-type.outputs.is-babel-8 == 'false'
# env:
# YARN_NPM_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Publish to npm (Babel 8)
run: yarn release-tool publish --yes --tag next
if: needs.check-release-type.outputs.is-babel-8 == 'true'
env:
YARN_NPM_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
BABEL_8_BREAKING: true
USE_ESM: true
# - name: Publish to npm (Babel 8)
# # --tag-version-prefix must match the one set in `make new-babel-8-version-create-branch`
# run: yarn release-tool publish --yes --tag next --tag-version-prefix tmp.v
# if: needs.check-release-type.outputs.is-babel-8 == 'true'
# env:
# YARN_NPM_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
# BABEL_8_BREAKING: true
# USE_ESM: true

github-release:
name: Create GitHub release draft
Expand All @@ -147,8 +156,7 @@ jobs:
if: |
always() &&
(needs.git-version.result == 'success' || needs.git-version.result == 'skipped') &&
needs.check-release-type.result == 'success' &&
needs.check-release-type.outputs.is-babel-8 == 'false'
needs.check-release-type.result == 'success'
outputs:
is-main: ${{ steps.is-main.outputs.result == 1 }}
changelog: ${{ steps.changelog.outputs.changelog }}
Expand All @@ -162,7 +170,7 @@ jobs:
id: is-main
uses: babel/actions/ref-matches-branch@v2
with:
name: main
name: new-babel-8-release-process

- name: Checkout the temporary branch
if: needs.git-version.result == 'success'
Expand All @@ -171,13 +179,28 @@ jobs:
- name: Get tag info
id: tags
uses: babel/actions/get-release-tags@v2
with:
# GitHub workflow do not support the ternary operator:
# https://github.com/actions/runner/issues/409
# `a && b || c` is equivalent to `a ? b : c` if `b` is truthy
prefix: ${{ needs.check-release-type.outputs.is-babel-8 == 'true' && 'v8' || 'v7' }}

- name: Use Babel 8 PR labels
if: needs.check-release-type.outputs.is-babel-8 == 'true'
run: |
node -e "
const pkg = require('./package.json');
pkg.changelog.labels = pkg.changelog.labels_breaking
fs.writeFileSync('package.json', JSON.stringify(pkg, null, 2))
"
- name: Generate the changelog
id: changelog
uses: babel/actions/generate-lerna-changelog@v2
with:
from: ${{ steps.tags.outputs.old }}
to: ${{ steps.tags.outputs.new }}
filter: ${{ needs.check-release-type.outputs.is-babel-8 == 'true' && 'v8' || 'v7' }}
env:
GITHUB_AUTH: ${{ secrets.GITHUB_TOKEN }}

Expand All @@ -186,14 +209,18 @@ jobs:
with:
tag: ${{ steps.tags.outputs.new }}
changelog: ${{ steps.changelog.outputs.changelog }}
token: ${{ secrets.BOT_TOKEN }}
token: ${{ secrets.GITHUB_TOKEN }}

github-push:
permissions:
contents: write # for Git to git push
name: Push release commit to "main"
runs-on: ubuntu-latest
needs: [npm-release, github-release, git-version]
needs:
- npm-release
- github-release
- git-version
- check-release-type
# The default condition is success(), but this is false when one of the previous jobs is skipped
if: |
always() &&
Expand All @@ -208,20 +235,26 @@ jobs:
if: needs.git-version.result == 'success'
run: git checkout ${{ needs.git-version.outputs.branch }}

- name: Get changelog file name
id: filename
run: |
echo "filename=${{ needs.check-release-type.outputs.is-babel-8 == 'true' && '.github/CHANGELOG-v8.md' || 'CHANGELOG.md' }}" >> $GITHUB_OUTPUT
- name: Update CHANGELOG.md
uses: babel/actions/update-changelog@v2
with:
changelog: ${{ needs.github-release.outputs.changelog }}
filename: ${{ steps.filename.outputs.filename }}

- name: Commit CHANGELOG.md
run: |
git add CHANGELOG.md
git add ${{ steps.filename.outputs.filename }}
git -c user.name="Babel Bot" -c user.email="[email protected]" \
commit -m "Add ${{ needs.github-release.outputs.version }} to CHANGELOG.md [skip ci]" --no-verify --quiet
commit -m "Add ${{ needs.github-release.outputs.version }} to ${{ steps.filename.outputs.filename }} [skip ci]" --no-verify --quiet
- name: Push to GitHub
run: |
git push "https://babel-bot:${{ secrets.GITHUB_TOKEN }}@github.com/${GITHUB_REPOSITORY}.git" HEAD:main --follow-tags
git push "https://babel-bot:${{ secrets.GITHUB_TOKEN }}@github.com/${GITHUB_REPOSITORY}.git" HEAD:new-babel-8-release-process --follow-tags
- name: Delete temporary branch from GitHub
if: needs.git-version.result == 'success'
Expand Down
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,12 @@ new-version:
new-babel-8-version:
$(MAKEJS) new-babel-8-version

new-babel-8-version-create-commit:
$(MAKEJS) new-babel-8-version-create-commit

new-babel-8-version-create-commit-ci:
$(MAKEJS) new-babel-8-version-create-commit-ci

# NOTE: Run make new-version first
publish:
@echo "Please confirm you have stopped make watch. (y)es, [N]o:"; \
Expand Down
2 changes: 1 addition & 1 deletion Makefile.js

Large diffs are not rendered by default.

43 changes: 34 additions & 9 deletions Makefile.source.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ target["new-version"] = function () {
yarn(["release-tool", "version", "-f", "@babel/standalone"]);
};

target["new-babel-8-version-prepare"] = function () {
target["new-babel-8-version"] = function () {
exec("git", ["pull", "--rebase"]);

const pkg = JSON.parse(readFileSync("./package.json", "utf8"));
Expand All @@ -484,14 +484,14 @@ target["new-babel-8-version-prepare"] = function () {
writeFileSync("./package.json", JSON.stringify(pkg, null, 2) + "\n");
exec("git", ["add", "./package.json"]);
exec("git", ["commit", "-m", "Bump Babel 8 version to " + nextVersion]);
exec("git", ["tag", `v${nextVersion}`, "-m", `v${nextVersion}`]);

return nextVersion;
};

target["new-babel-8-version"] = function () {
const nextVersion = target["new-babel-8-version-prepare"]();

exec("git", ["checkout", "-b", "release/v" + nextVersion]);
function bumpVersionsToBabel8Pre() {
const pkg = JSON.parse(readFileSync("./package.json", "utf8"));
const nextVersion = pkg.version_babel8;

SOURCES.forEach(source => {
readdirSync(source).forEach(name => {
Expand All @@ -504,9 +504,34 @@ target["new-babel-8-version"] = function () {
});
});

yarn(["release-tool", "version", nextVersion, "--all"]);
return nextVersion;
}

console.log(
`Run \`git push upstream main release/v${nextVersion} --follow-tags\` to push the changes on GitHub and release them.`
);
target["new-babel-8-version-create-commit-ci"] = function () {
const nextVersion = bumpVersionsToBabel8Pre();
yarn([
"release-tool",
"version",
nextVersion,
"--all",
"--tag-version-prefix",
"tmp.v",
"--yes",
]);
};

target["new-babel-8-version-create-commit"] = function () {
const pkg = JSON.parse(readFileSync("./package.json", "utf8"));
const nextVersion = pkg.version_babel8;
exec("git", ["checkout", "-b", `release/temp/v${nextVersion}`]);
yarn([
"release-tool",
"version",
nextVersion,
"--all",
"--tag-version-prefix",
"tmp.v",
]);

console.log("Run `BABEL_8_BREAKING-true make publish` to finish publishing");
};

0 comments on commit 7b4531d

Please sign in to comment.