Skip to content

Commit

Permalink
fix: full git history in CI & filter tags for release notes (#2364)
Browse files Browse the repository at this point in the history
* initial steps to separate

* fix: separate pack&upload for manual runs

* fix: get all history from git so we have tags.

* fix: assume branch is in correct state in CI. Filter out tags to only get those starting with "v" and not containing "-" (dist tags)

* fix: use correct job name for it
  • Loading branch information
ryandagg committed May 24, 2023
1 parent cb1bf68 commit 23419d9
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 59 deletions.
@@ -1,56 +1,11 @@
name: Publish, Pack and Upload
name: Pack and Upload

on:
workflow_dispatch:
inputs:
isPreRelease:
description: is release for beta/rc/dev?
type: boolean
required: false
default: false

workflow_call:
inputs:
isPreRelease:
description: is release not for prod?
type: boolean
required: false
default: false

jobs:
publish-npm-and-github:
runs-on: pub-hk-ubuntu-22.04-small
permissions:
# give secrets.GITHUB_TOKEN ability to push/tag/release
contents: write
steps:
- uses: actions/checkout@v3
- name: Use Node.js 16.x
uses: actions/setup-node@v3
with:
node-version: 16.x
cache: yarn
- run: yarn --frozen-lockfile --network-timeout 1000000
- name: set NPM auth
run: echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_PUBLISH_KEY }}" > ~/.npmrc
- name: set git user
run: |
git config user.name "GitHub Actions Bot"
git config user.email "heroku-front-end+npm-releases@salesforce.com"
- name: Publish to NPM & GitHub release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
if ${{ inputs.isPreRelease }}
then
bash scripts/publish-prerelease
else
bash scripts/publish-release
fi
shell: bash

pack_deb:
needs: [publish-npm-and-github]
# ubuntu started using a compression method after this version that debian currently does not support
# https://github.com/heroku/cli/pull/2245#issue-1590017122
runs-on: ubuntu-20.04
Expand Down
53 changes: 53 additions & 0 deletions .github/workflows/publish-npm-gh.yml
@@ -0,0 +1,53 @@
name: Publish NPM & Github Release

on:
workflow_dispatch:
inputs:
isPreRelease:
description: is release for beta/rc/dev?
type: boolean
required: false
default: false

workflow_call:
inputs:
isPreRelease:
description: is release for beta/rc/dev?
type: boolean
required: false
default: false

jobs:
publish-npm-and-github:
runs-on: pub-hk-ubuntu-22.04-small
permissions:
# give secrets.GITHUB_TOKEN ability to push/tag/release
contents: write
steps:
- uses: actions/checkout@v3
with:
# checkout entire repo, not just this branch. Tags are needed release script
fetch-depth: 0
- name: Use Node.js 16.x
uses: actions/setup-node@v3
with:
node-version: 16.x
cache: yarn
- run: yarn --frozen-lockfile --network-timeout 1000000
- name: set NPM auth
run: echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_PUBLISH_KEY }}" > ~/.npmrc
- name: set git user
run: |
git config user.name "GitHub Actions Bot"
git config user.email "heroku-front-end+npm-releases@salesforce.com"
- name: Publish to NPM & GitHub release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
if ${{ inputs.isPreRelease }}
then
bash scripts/publish-prerelease
else
bash scripts/publish-release
fi
shell: bash
13 changes: 9 additions & 4 deletions .github/workflows/trigger-release.yml
Expand Up @@ -23,19 +23,24 @@ jobs:
with:
path: './packages/cli/package.json'

publish-pack-upload:
publish:
needs: [get-version-channel]
# if (merged PR && is release branch) OR (prerelease branch && has a channel on the package.json version)
# channel is checked to avoid deploying prod from a malformed prerelease branch
if: (github.event.pull_request.merged == true && contains(github.ref, 'release-')) || (needs.get-version-channel.outputs.channel && contains(github.ref, 'prerelease/'))
uses: ./.github/workflows/publish-pack-upload.yml
uses: ./.github/workflows/publish-npm-gh.yml
with:
isPreRelease: ${{ !!needs.get-version-channel.outputs.channel }}
secrets: inherit

pack-upload:
needs: [ publish ]
uses: ./.github/workflows/pack-upload.yml
secrets: inherit

promote:
needs: [get-version-channel, publish-pack-upload]
if: needs.publish-pack-upload.result == 'success'
needs: [get-version-channel, pack-upload]
if: needs.pack-upload.result == 'success'
uses: ./.github/workflows/promote-release.yml
with:
version: ${{ needs.get-version-channel.outputs.version }}
Expand Down
13 changes: 4 additions & 9 deletions scripts/publish-release
Expand Up @@ -25,12 +25,6 @@ if !(gh auth status --hostname "github.com" > /dev/null 2>&1); then
exit 1
fi

git pull --rebase origin "${CURRENT_BRANCH}"
# The --force overrides local tags.
# This is needed if you've published the CLI previously,
# otherwise git will exit with an error unnecessarily.
git fetch origin --force --tags

PACKAGE_VERSION=`node -e "console.log(require('./lerna.json').version)"`
TAG_NAME="v${PACKAGE_VERSION}"
EXISTING_REMOTE_TAG=$(git ls-remote origin "refs/tags/${TAG_NAME}")
Expand All @@ -50,11 +44,12 @@ echo "Done installing dependencies with yarn"
echo "publishing packages to npm..."
yarn lerna publish --yes from-package


LAST_PUBLISHED_TAG=$(git tag --sort="-version:refname" --list --format="%(refname:strip=2)" | head -n1)

git tag "${TAG_NAME}" -m "${TAG_NAME}"
git push origin "${TAG_NAME}"

SORTED_TAGS=$(git tag --sort="-version:refname" --list --format="%(refname:strip=2)")
FILTERED_TAGS=$(echo ${SORTED_TAGS} | grep 'v[0-9.]*' | grep -v '-')
LAST_PUBLISHED_TAG=$(echo ${FILTERED_TAGS} | head -n1)

RELEASE_NOTES=$(git log --graph --format="%h %s" "${LAST_PUBLISHED_TAG}...${TAG_NAME}~1")
gh release create "${TAG_NAME}" --title="${TAG_NAME}" --notes="${RELEASE_NOTES}"

0 comments on commit 23419d9

Please sign in to comment.