Skip to content

[AAWF-249] Release workflow #2260

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

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
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
113 changes: 0 additions & 113 deletions .github/workflows/prepare_release.yml

This file was deleted.

21 changes: 0 additions & 21 deletions .github/workflows/prerelease.yml

This file was deleted.

36 changes: 29 additions & 7 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,38 @@ permissions:

on:
release:
types: [released]
types:
- prereleased
- released
jobs:
build:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
fetch-depth: 1
- uses: actions/setup-node@v3
with:
node-version: 16
- run: yarn
- run: yarn publish --tag=latest
node-version: 18
- name: Releasing tag ${{ github.event.release.tag_name }}
run: |
corepack enable; yarn

# Get tag name from event
tag_name="${{ github.event.release.tag_name }}"

if [[ ! "$tag_name" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
cd $(echo $tag_name | rev | cut -d'/' -f2- | rev)
fi

cmd="yarn npm publish --access public"
if [ "${{ github.event.release.prerelease }}" == "true" ]; then
cmd+=" --tag=beta"
else
cmd+=" --tag=latest"
fi

eval $cmd
env:
NPM_AUTH_TOKEN: ${{ secrets.YARN_NPM_AUTH_TOKEN }}
YARN_NPM_AUTH_TOKEN: ${{ secrets.YARN_NPM_AUTH_TOKEN }}
COREPACK_ENABLE_DOWNLOAD_PROMPT: 0
120 changes: 57 additions & 63 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ on:
types: [closed]
branches:
- master
- v2

jobs:
create_release:
Expand All @@ -22,77 +23,70 @@ jobs:
steps:
- name: Get GitHub App token
id: get_token
uses: actions/create-github-app-token@v1
uses: actions/create-github-app-token@c1a285145b9d317df6ced56c09f525b5c2b6f755 #v1.11.1
with:
app-id: ${{ secrets.PIPELINE_GITHUB_APP_ID }}
private-key: ${{ secrets.PIPELINE_GITHUB_APP_PRIVATE_KEY }}

- name: Create release
uses: actions/github-script@v6
env:
RELEASE_BRANCH: ${{ github.head_ref }}
with:
github-token: ${{ steps.get_token.outputs.token }}
script: |
const tagName = `v${process.env.RELEASE_BRANCH.split("/")[1]}`;
await github.rest.git.createRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: `refs/tags/${tagName}`,
sha: context.payload.pull_request.merge_commit_sha,
});
await github.rest.repos.createRelease({
owner: context.repo.owner,
repo: context.repo.repo,
generate_release_notes: true,
tag_name: tagName,
});

- uses: actions/checkout@v3
- name: Checkout ${{ github.event.pull_request.base.ref }}
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
fetch-depth: 0
token: ${{ steps.get_token.outputs.token }}
ref: ${{ github.event.pull_request.base.ref }}
fetch-depth: 0

- name: Setup Git
- name: Release packages
env:
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
BASE_SHA: ${{ github.event.pull_request.base.sha }}
GH_TOKEN: ${{ steps.get_token.outputs.token }}
shell: bash
run: |
git config user.name "${GIT_AUTHOR_NAME}"
git config user.email "${GIT_AUTHOR_EMAIL}"
CHANGED_PACKAGE_JSON_FILES=$(git diff --diff-filter=MACR --name-only $BASE_SHA...$HEAD_SHA \
| grep -E 'package\.json$' \
| xargs dirname \
| sort \
| uniq)

- name: Set up Node
uses: actions/setup-node@v3
with:
node-version: 16
cache: 'yarn'
declare -A versions
for package in $CHANGED_PACKAGE_JSON_FILES; do
base_version=$(git show $BASE_SHA:$package/package.json | jq -r .version)
head_version=$(git show $HEAD_SHA:$package/package.json | jq -r .version)

- name: Bump version
run: |
git switch -c "${POST_RELEASE_BRANCH}"
# TODO remove beta after 1.0.0 release
npm version --no-git-tag-version --preid beta prerelease
git commit -a -m "Bump version"
git push -f --set-upstream origin "${POST_RELEASE_BRANCH}"
env:
POST_RELEASE_BRANCH: post-${{ github.head_ref }}
if [ "$base_version" != "$head_version" ]; then
versions[$package]=$head_version
fi
done

- name: Create PR
uses: actions/github-script@v6
env:
POST_RELEASE_BRANCH: post-${{ github.head_ref }}
BASE: master
with:
github-token: ${{ steps.get_token.outputs.token }}
script: |
const { data: pr } = await github.rest.pulls.create({
owner: context.repo.owner,
repo: context.repo.repo,
head: process.env.POST_RELEASE_BRANCH,
base: process.env.BASE,
title: "Post release",
body: "Bump to dev version",
});
await github.rest.issues.addLabels({
issue_number: pr.number,
owner: context.repo.owner,
repo: context.repo.repo,
labels: ["changelog/no-changelog"],
});
for package in "${!versions[@]}"; do
echo "Releasing $package at version ${versions[$package]}"

# Build the tag name
if [[ "$package" == "." ]]; then
# If the package is the root, use the version as the tag name
tag_name="v${versions[$package]}"
else
# If the package is not the root, use the package name and version as the tag name
tag_name="$package/${versions[$package]}"
fi

# Get the changelog entries since last release
# TODO: Implement this
# changelog_content=$(git diff $BASE_REF...$HEAD_REF -- $package/CHANGELOG.md | grep -A 1000 "^+##" | grep -v "^+++" | sed 's/^+//')

is_prerelease=$(echo $package | grep -q "beta" && echo true || echo false)
# Create the tag
gh api repos/{owner}/{repo}/git/refs \
-f ref="refs/tags/$tag_name" \
-f sha=$HEAD_SHA

# Create the release
gh api repos/{owner}/{repo}/releases --input - << EOF
{
"tag_name": "$tag_name",
"name": "$tag_name",
"body": "See $package/CHANGELOG.md for details",
"prerelease": $is_prerelease
}
EOF
done
38 changes: 0 additions & 38 deletions RELEASING.md

This file was deleted.