diff --git a/.github/workflows/create-github-release.yaml b/.github/workflows/create-github-release.yaml new file mode 100644 index 00000000..f417cf99 --- /dev/null +++ b/.github/workflows/create-github-release.yaml @@ -0,0 +1,36 @@ +name: Create GitHub Release + +on: + push: + tags: + - '@itwin/*_v[0-9]+.[0-9]+.[0-9]+' + workflow_dispatch: + +jobs: + create-release: + runs-on: ubuntu-latest + + steps: + - name: Checkout tag + uses: actions/checkout@v4 + with: + ref: ${{ github.ref }} # checkouts the branch that triggered the workflow + fetch-depth: 0 + + - name: Install pnpm + uses: pnpm/action-setup@v4 + + - name: Install dependencies + run: pnpm install + + - name: Configure git + run: | + git config --local user.email imodeljs-admin@users.noreply.github.com + git config --local user.name imodeljs-admin + + - name: Create GitHub release + run: | + echo "Creating GitHub release for tag ${{ github.ref }}" + bash .github/workflows/scripts/create-release.sh ${{ github.ref }} + env: + GITHUB_TOKEN: ${{ secrets.IMJS_ADMIN_GH_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/create-release.yaml b/.github/workflows/publish-packages.yaml similarity index 72% rename from .github/workflows/create-release.yaml rename to .github/workflows/publish-packages.yaml index b3d3fe43..1e6a7b05 100644 --- a/.github/workflows/create-release.yaml +++ b/.github/workflows/publish-packages.yaml @@ -1,6 +1,4 @@ -# Workflow that will create a GitHub release a when a new release tag is pushed - -name: Create Release +name: Publish Packages to npm on: workflow_dispatch @@ -18,19 +16,13 @@ jobs: - name: Install pnpm uses: pnpm/action-setup@v4 - - name: Use Node.js 18 - uses: actions/setup-node@v3 - with: - node-version: 18.x - registry-url: https://registry.npmjs.org/ - - name: Install dependencies run: pnpm install - name: Build, Lint, Test run: pnpm lage build lint cover - - name: Publish packages + - name: Publish packages and create git tags run: | git config --local user.email imodeljs-admin@users.noreply.github.com git config --local user.name imodeljs-admin diff --git a/.github/workflows/scripts/create-release.sh b/.github/workflows/scripts/create-release.sh new file mode 100644 index 00000000..a2d2b7f4 --- /dev/null +++ b/.github/workflows/scripts/create-release.sh @@ -0,0 +1,66 @@ +#!/bin/bash + +if [ -z "$1" ]; then + echo "No refName was supplied" + exit 1 +fi + +refName=$1 +echo "Ref name passed in: $refName" + +tagName=$(echo $refName | sed 's/refs\/tags\///') +echo "Tag name was parsed as: $tagName" +packageName=$(echo $tagName | sed 's/_v.*//') +echo "Package name was parsed as: $packageName" +packageVersion=$(echo $tagName | sed 's/.*_v//') +echo "Package version was parsed as: $packageVersion" + +# The packageDirectory variable is determined by searching the ./packages directory for a subdirectory +# that contains a package.json file with a name matching the parsed packageName. +# determine package directory so that we can zip it up and also find the changelog +packageDirectory=$(find ./packages -maxdepth 1 -type d | while read dir; do + if [ -f "$dir/package.json" ]; then + packageNameInJson=$(jq -r '.name' "$dir/package.json") + if [ "$packageNameInJson" == "$packageName" ]; then + echo "$dir" + break + fi + fi +done) + +if [ -z "$packageDirectory" ]; then + echo "No package directory found for package name: $packageName" + exit 1 +else + echo "Package directory was determined as: $packageDirectory" +fi + +cd $packageDirectory + +changelogMd="CHANGELOG.md" +if [ ! -f "$changelogMd" ]; then + echo "Changelog file not found: $changelogMd" + exit 1 +fi + +# build the package and create consumable to release +pnpm build + +# Extract the changelog text +releaseNoteText=$(awk -v version="$packageVersion" '$0 ~ version {flag=1; print; next} /^## /{flag=0} flag' "$changelogMd") +echo "Release note text was extracted as: $releaseNoteText" + +# remove the @itwin/ or @bentley/ scope from the tag name to create the zip file name since they have special characters +zipFileName=$(echo "$tagName" | sed 's/@itwin\///; s/@bentley\///') +echo "Zip file name was parsed as: $zipFileName" + +# Zip the package deliverables - lib and dist directories +zip -r "$zipFileName.zip" lib dist +tar -czvf "$zipFileName.tar.gz" lib dist + +# Create a release and upload assets +gh release create "$tagName" \ + "$zipFileName.zip" \ + "$zipFileName.tar.gz" \ + --notes "$releaseNoteText" \ + --verify-tag