fix(release): fix checkout branch and commit message #423
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Release | |
# triggers on pushes to the 'prod' branch | |
on: | |
push: | |
# NOTE(thuang): Since REGEX is not supported for branches, we cannot target | |
# any versioned branch: "+([0-9])?(.{+([0-9]),x}).x" as specified in | |
# .releaserc.js. So we'll need to manually add such branch's name here manually | |
branches: | |
- prod | |
jobs: | |
# Job 1 | |
release: | |
name: Release | |
runs-on: ubuntu-latest # Use the latest version of the Ubuntu runner environment | |
steps: | |
# Step 1: Check out the repository code | |
- name: Checkout | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
# Step 2: Set up Node.js environment and cache Yarn dependencies | |
- name: Setup Node.js and Cache yarn | |
uses: actions/setup-node@v3 | |
with: | |
node-version-file: ".node-version" # Specify the Node.js version from '.node-version' file | |
cache: "yarn" # Cache Yarn dependencies for faster builds | |
# Step 3: Set up npm and authentication | |
- name: "Setup npm" | |
run: | | |
npm set "//registry.npmjs.org/:_authToken=${NODE_AUTH_TOKEN}" | |
env: | |
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
# Step 4: Ensure npm access | |
- name: Ensure NPM access | |
run: npm whoami | |
env: | |
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
# Step 5: Install project dependencies using Yarn | |
- name: Install dependencies | |
run: yarn ci | |
# Step 6: Build the component library in 'dist/' directory | |
- name: Build component library in dist/ | |
run: yarn build | |
# Step 7: Configure git user for pushing release changes back to prod branch | |
- name: Config git user | |
run: | | |
git config --global user.name "${{ github.actor }}" | |
git config --global user.email "${{ github.actor }}@users.noreply.github.com" | |
# Step 8: Lerna Version | |
- name: Lerna Version | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
NPM_TOKEN: ${{ secrets.NPM_TOKEN }} | |
run: yarn version:ci | |
# Step 9: Commit changes | |
- name: Commit changes | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
uses: stefanzweifel/git-auto-commit-action@v4 | |
with: | |
commit_message: "chore(release): Publish" | |
branch: ${{ github.head_ref }} | |
# Step 10: Publish NPM packages | |
- name: Lerna Publish | |
env: | |
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}} | |
run: yarn publish:ci | |
# Step 11: Post breaking changes to a Slack channel | |
- name: Post breaking changes to a Slack channel | |
env: | |
SLACK_WEBHOOK_URL: ${{ secrets.SDS_BREAKING_CHANGES_SLACK_WEBHOOK }} | |
uses: act10ns/slack@v1 | |
with: | |
status: complete | |
channel: "#sci-design-system-breaking-changes" | |
config: .github/config/slack.yml | |
if: contains(toJson(github.event.commits.*.message), 'BREAKING CHANGE') | |
# Job 2 | |
create-version-matrix: | |
needs: release | |
runs-on: ubuntu-latest | |
outputs: | |
matrix: ${{ steps.set-matrix.outputs.matrix }} | |
steps: | |
# Step 1: Check out the repository code | |
- name: Checkout Repository | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
ref: prod | |
# Step 2: Create a matrix of package versions and names | |
- name: Create Versions Matrix | |
id: set-matrix | |
run: | | |
matrix="[" | |
for package_json in $(find ./packages -name package.json); do | |
version=$(jq -r .version "$package_json") | |
name=$(jq -r .name "$package_json") | |
matrix="${matrix}{\"name\":\"${name}\", \"version\":\"${version}\"}," | |
done | |
matrix="${matrix%,}" # Remove trailing comma | |
matrix="${matrix}]" # Close the JSON array | |
echo "matrix=${matrix}" >> $GITHUB_OUTPUT | |
# Job 3 | |
create-github-release: | |
needs: create-version-matrix | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
cfg: ${{fromJson(needs.create-version-matrix.outputs.matrix)}} | |
steps: | |
# Step 1: Create a GitHub release for the latest version | |
- name: Release | |
uses: softprops/action-gh-release@v1 | |
with: | |
tag_name: "${{ matrix.cfg.name }}@${{ matrix.cfg.version }}" |