Skip to content

Commit 3c28bb5

Browse files
authored
Merge pull request #210 from Expensify/cmartins-automaticallyPublishToNPM
2 parents 9792e95 + f3b1ec2 commit 3c28bb5

File tree

4 files changed

+77
-31
lines changed

4 files changed

+77
-31
lines changed
5.01 KB
Binary file not shown.

.github/workflows/npmpublish.yml

Lines changed: 0 additions & 31 deletions
This file was deleted.

.github/workflows/publish.yml

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
name: Publish package to npmjs
2+
3+
# This workflow runs when code is pushed to `main` (i.e: when a pull request is merged)
4+
on:
5+
push:
6+
branches: [main]
7+
8+
# Ensure that only one instance of this workflow executes at a time.
9+
# If multiple PRs are merged in quick succession, there will only ever be one publish workflow running and one pending.
10+
concurrency: ${{ github.workflow }}
11+
12+
jobs:
13+
version:
14+
runs-on: ubuntu-latest
15+
16+
# OSBotify will update the version on `main`, so this check is important to prevent an infinite loop
17+
if: ${{ github.actor != 'OSBotify' }}
18+
19+
steps:
20+
- uses: actions/checkout@v4
21+
with:
22+
ref: main
23+
# The OS_BOTIFY_COMMIT_TOKEN is a personal access token tied to osbotify, which allows him to push to protected branches
24+
token: ${{ secrets.OS_BOTIFY_COMMIT_TOKEN }}
25+
26+
- name: Decrypt & Import OSBotify GPG key
27+
run: |
28+
cd .github
29+
gpg --quiet --batch --yes --decrypt --passphrase="$LARGE_SECRET_PASSPHRASE" --output OSBotify-private-key.asc OSBotify-private-key.asc.gpg
30+
gpg --import OSBotify-private-key.asc
31+
env:
32+
LARGE_SECRET_PASSPHRASE: ${{ secrets.LARGE_SECRET_PASSPHRASE }}
33+
34+
- name: Set up git for OSBotify
35+
run: |
36+
git config --global user.signingkey 367811D53E34168C
37+
git config --global commit.gpgsign true
38+
git config --global user.name OSBotify
39+
git config --global user.email infra+osbotify@expensify.com
40+
41+
- uses: actions/setup-node@v4
42+
with:
43+
node-version-file: ".nvmrc"
44+
45+
- name: Install npm packages
46+
run: npm ci
47+
48+
- name: Update npm version
49+
run: npm version patch
50+
51+
- name: Set new version in GitHub ENV
52+
run: echo "NEW_VERSION=$(jq '.version' package.json)" >> $GITHUB_ENV
53+
54+
- name: Push branch and publish tags
55+
run: git push origin main && git push --tags
56+
57+
- name: Build package
58+
run: npm run build
59+
60+
- name: Publish to npm
61+
run: npm publish
62+
env:
63+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
64+
65+
- name: Get merged pull request
66+
id: getMergedPullRequest
67+
run: |
68+
read -r number < <(gh pr list --search ${{ github.sha }} --state merged --json 'number' | jq -r '.[0] | [.number] | join(" ")')
69+
echo "number=$number" >> "$GITHUB_OUTPUT"
70+
env:
71+
GITHUB_TOKEN: ${{ github.token }}
72+
73+
- name: Comment on merged pull request
74+
run: gh pr comment ${{ steps.getMergedPullRequest.outputs.number }} --body "🚀Published to npm in v${{ env.NEW_VERSION }}"
75+
env:
76+
GITHUB_TOKEN: ${{ github.token }}

.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
20.15.1

0 commit comments

Comments
 (0)