-
Notifications
You must be signed in to change notification settings - Fork 12
160 lines (131 loc) · 6.37 KB
/
npm-release.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# This is a basic workflow to help you get started with Actions
name: Release to npm
# -- steps for larva release, for reference
# this action would be triggered by: a button in the Actions tab
# start at the master branch
# checkout a release branch from master,
# increment the name (assume minor releases most of the time) by reading lerna json file
# run git checkout
# assume changelog has been updated
# run npx lerna publish
# asks if minor/major release, user has to manually type. probably https://github.com/lerna/lerna/tree/main/commands/version#options
# try running npx lerna publish minor --yes
# create a PR to merge release branch to master
# at least one human approval required (nice to have: auto ping #larva channel asking for PR approval)
# pipelines have to pass
# manual merge required (nice to have: have a machine user w/ token in the allowlist that can bypass)
# tag latest release on repo
# Controls when the workflow will run
# Allows you to run this workflow manually from the Actions tab
# docs: https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#workflow_dispatch
# https://docs.github.com/en/actions/managing-workflow-runs/manually-running-a-workflow
on:
# For action testing! Will need to update this when merged to main for the button to trigger action.
push:
# UN-COMMENT THESE OUT NEXT TIME
branches:
- feature/automated-releases
# workflow_dispatch:
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
deploy-release:
name: Create and Deploy NPM Release
runs-on: ubuntu-latest
permissions: write-all
steps:
- name: Checkout master branch
uses: actions/checkout@v3
with:
ref: 'master'
fetch-depth: '0'
- name: Checkout release branch
run: |
git fetch --depth=500 origin +refs/tags/*:refs/tags/*
# Get latest release tag name
export VERSION=$(git describe --tags $(git rev-list --tags --max-count=1))
# Parsing the latest release tag name into an array
arrIN=(${VERSION//./ })
# Bump minor version by 1
export MINOR=$((arrIN[1]+1))
# prefix the branch with test-release for testing purposes.
export BRANCH_NAME="release/1.${MINOR}.0"
# export BRANCH_NAME="release/1.${MINOR}.0"
git checkout -b $BRANCH_NAME
git push --set-upstream origin $BRANCH_NAME
# Save the current branch name into an env variable.
echo "GH_BRANCH_NAME=$BRANCH_NAME" >> $GITHUB_ENV
# Save the minor version number into an env variable.
echo "GH_MINOR=$MINOR" >> $GITHUB_ENV
- name: Use Node 14
uses: actions/setup-node@v3
with:
node-version: '14'
registry-url: 'https://registry.npmjs.org'
- name: Lerna checks
run: |
npm run lint:scss
npx lerna --version
- name: Publish to npm
# https://dev.to/astagi/publish-to-npm-using-github-actions-23fn
# Check dist.dev NPM user in LastPass?
run: |
git config user.name pmc-machine-user
git config user.email "<>"
# Canary release for testing purposes. --prefix release with another-test
# npx lerna publish --canary --preid test-v3 --yes --tag-version-prefix='test-v' --no-git-reset
npx lerna publish minor --yes --no-git-reset
# Get the latest commits and declare latest commit into var
git fetch
export LATEST_HASH=$(git rev-list --tags --max-count=1)
# THIS IS NOT TAGGING TO THE ACTUAL RELEASE BRANCH?? ^
# See notice here (automation): https://github.com/penske-media-corp/pmc-larva/commit/35ceb11b3f561ba35a0d81da313316930d644c11
# vs lack of notice when doing it manually: https://github.com/penske-media-corp/pmc-larva/commit/b3385249708181dc1f48b4530bd3c10a387c3778
#
# REMEMBER TO UN-COMMENT THE ON-PUSH TRIGGER!
#
echo '🤩🤩 ➡️ Finished lerna publish'
git status
git add -A
# git add .
echo '🤩🤩 ➡️ Added working changes after lerna publish'
git commit -m 'Update package versioning'
echo '🤩🤩 ➡️ Committed package versioning update'
# Get latest commit from release tag and add it to release branch.
git status
echo '🤩🤩 ➡️ Finished committing'
git push
echo '🤩🤩 ➡️ Finish pushing first commit'
git cherry-pick $LATEST_HASH --keep-redundant-commits
echo '🤩🤩 ➡️ Cherry-picked $LATEST_HASH'
git --no-pager log -1 --pretty=format:"%h - %an, %ar : %s"
echo '🤩🤩 ➡️ Did git log after cherry-pick'
# git cherry-pick --continue
# git cherry-pick --skip
# echo '🤩🤩 ➡️ Finished cherry picking'
git diff
echo '🤩🤩 ➡️ Diffed after cherry-pick'
# git add -A
# echo '🤩🤩 ➡️ Added working changes post-cherry-pick'
# git commit -m "Cherry pick last commit from lerna"
# git commit --allow-empty -m "Cherry pick last commit from lerna"
# echo '🤩🤩 ➡️ Commit the cherry pick'
git push
echo '🤩🤩 ➡️ Push the cherry pick'
git status
echo '🤩🤩 ➡️ Status after the cherry pick push'
git diff
echo '🤩🤩 ➡️ Diff after the cherry pick push'
env:
# testing a fake secret to see if anything changes.
TEST_VAR: ${{ secrets.FAKE_FAKE }}
NODE_AUTH_TOKEN: ${{ secrets.NPM_ACCESS_TOKEN }}
- name: Create Pull Request
uses: peter-evans/[email protected]
with:
# token: ${{ github.token }}
branch: ${{ env.GH_BRANCH_NAME }}
base: master
title: Release v1.${{ env.GH_MINOR }}.0
# body: probably autofills the PR template that already exists for larva?
# Engineer will then have to go into CHANGELOG.md to update the changelog
# NEXT STEPS: Clean up, push up to main branch, test that the workflow trigger will work.