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

Introduce new release flow #2140

Closed
wants to merge 6 commits into from
Closed
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
48 changes: 25 additions & 23 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ jobs:

steps:
- uses: actions/checkout@v4
with:
token: ${{ secrets.GH_PAT }}

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
Expand Down Expand Up @@ -58,24 +56,28 @@ jobs:
run: |
yarn lerna publish from-package --yes --allowBranch=main --loglevel=verbose --dist-tag latest

# Commenting this out temporarily until we fix the release script to not rely on tags
# release:
# needs: build-and-publish # comment when testing locally with https://github.com/nektos/act
#
# runs-on: ubuntu-20.04
# timeout-minutes: 15
# steps:
# - uses: actions/checkout@v4
# with:
# fetch-depth: 0 # Shallow clones should be disabled for computing changelog
# fetch-tags: true
#
# - name: Create Github Release
# id: create-github-release
# uses: actions/github-script@v7
# env:
# RELEASE_TAG: ${{ steps.get-release-tag.outputs.release-tag }}
# with:
# script: |
# const script = require('./scripts/github-action/create-github-release.js')
# await script({github, context, core, exec})
# Commenting this out temporarily until we fix the release script to not rely on tags
release:
needs: build-and-publish # comment when testing locally with https://github.com/nektos/act

runs-on: ubuntu-20.04
timeout-minutes: 15
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Shallow clones should be disabled to ensure the commit history for the repository is available to the action
fetch-tags: true

- name: Generate Release Tag
id: get-release-tag
run: ./scripts/generate-release-tags.sh

- name: Create Github Release
id: create-github-release
uses: actions/github-script@v7
env:
RELEASE_TAG: ${{ steps.get-release-tag.outputs.release-tag }}
with:
script: |
const script = require('./scripts/github-action/create-github-release.js')
await script({github, context, core, exec})
69 changes: 69 additions & 0 deletions .github/workflows/version-packages.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# This workflow is triggered manually via the GitHub Actions page or API
name: Version Packages
on:
# workflow_dispatch:
# inputs:
# branch:
# description: 'Branch to create PR from'
# required: true
# default: 'release-actions'
push:
branches:
- new-prod-release-workflow

jobs:
build-and-version-packages:
env:
HUSKY: 0
runs-on: ubuntu-latest
permissions:
pull-requests: write
contents: write
steps:
- uses: actions/checkout@v4
with:
ref: main
fetch-depth: 0

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
registry-url: 'https://registry.npmjs.org'
cache: yarn

- name: Checkout branch
run: |
git checkout -b release-test
git push origin release-test

- name: Install Dependencies
run: yarn install --frozen-lockfile --ignore-optional

- name: Configure git
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"

- name: Test Github Output
run: |
"hello=world" >> "$GITHUB_OUTPUT"

# - name: Build
# run: NODE_ENV=production yarn build
#
# - name: Version Packages
# run: yarn lerna version minor --allow-branch release-test --no-git-tag-version --no-commit-hooks --no-private --yes
#
# - name: Commit and push
# run: yarn release release-test
#
# - name: Create PR
# run: |
# packages_published=$(git status -s -uno| grep "package.json" |awk '{print $2}'| xargs jq -r '.name + "@" + .version' --argjson null {})
# pr_message="This PR was opened by GithHub Actions. Whenever you're ready to publish the packages, merge this PR."
# description="$(printf "%s\n # Packages\n%s" "$pr_message" "$packages_published")"
# pr_url=$(gh pr create --base main --head release-test --title "Publish" --body "$description" --draft)
# echo "pr_url=$pr_url" >> "$GITHUB_OUTPUT"
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
"cloud": "yarn workspace @segment/action-destinations",
"core": "yarn workspace @segment/actions-core",
"lint": "ls -d ./packages/* | xargs -I {} eslint '{}/**/*.ts' --cache",
"postversion": "bash scripts/postversion.sh",
"prepare": "husky install",
"release": "bash scripts/release.sh",
"shared": "yarn workspace @segment/actions-shared",
Expand Down
25 changes: 24 additions & 1 deletion scripts/postversion.sh → scripts/generate-release-tags.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,32 @@
set -e
sha=$(git rev-parse HEAD);
branch=$(git rev-parse --symbolic-full-name --abbrev-ref HEAD);
message=$(git log -1 --pretty=%B);

if [[ $branch != "main" && $branch != "release" ]];
then
echo "Skipping release tag generation as branch is not main or release"
exit 0
fi;

if [[ $message != *"Publish"* ]];
then
echo "Skipping release tag generation as last commit is not a publish commit"
exit 0
fi;

# check if jq is installed
if ! command -v jq &> /dev/null
then
echo "jq could not be found. Please install jq to generate release tag."
exit 1
fi

# Generate and push release tag. Release tag format: release-YYYY-MM-DD[.N] e.g. release-2024-01-01
if ! n=$(git rev-list --count $sha~ --grep "Publish" --since="00:00"); then
echo 'Failed to compute release tag. Exiting.'
exit 1
else
else
case "$n" in
0) suffix="" ;; # first commit of the day gets no suffix
*) suffix=".$n" ;; # subsequent commits get a suffix, starting with .1
Expand All @@ -26,3 +40,12 @@ else
echo "Tagging $sha with $tag"
git tag -a $tag -m "Release $tag"
fi

# this script assumes the last commit was publish commit and gets all package.json files changed in the last commit
# and generates tags for each package.json file.
files=$(git show --pretty="" --name-only HEAD | grep -Ei '^packages/.*package\.json$')
for file in $files; do
tag=$(cat $file | jq -r '.name + "@" + .version')
echo "Tagging $sha with $tag"
git tag -a $tag -m "Release $tag"
done
25 changes: 21 additions & 4 deletions scripts/release.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,29 @@
#!/bin/bash
branch=$(git rev-parse --symbolic-full-name --abbrev-ref HEAD);

if [[ $branch != "main" && $branch != "release" ]];
branch=$1

# If no branch is provided, we get the current branch
if [[ -z $branch ]];
then
branch=$(git rev-parse --symbolic-full-name --abbrev-ref HEAD);
fi;

if [[ $branch == "main" || $branch == "release" ]];
then
echo "You must be on the main or relesase branch to release"
echo "You must not be on the main or release branch to release"
exit
fi;

git pull --ff-only
echo "Running lerna version minor..."
lerna version minor --no-private -y

# We generate package tags on our own on main branch. So, we need don't want lerna to do it for us.
lerna version minor --allow-branch "$branch" --no-git-tag-version --no-private --yes

# We commit results of lerna version to the branch
git add .

# Add the packages published to the commit description
packages_published=$(git status -s -uno| grep "package.json" |awk '{print $2}'| xargs jq -r '.name + "@" + .version' --argjson null {})
git commit -m "Publish" -m "$packages_published"
git push origin "$branch"
Loading