Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add workflow for auto publishing the repo to NPM #2

Merged
merged 2 commits into from
Jul 25, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .github/OSBotify-private-key.asc.gpg
Binary file not shown.
89 changes: 89 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
name: Publish package to npmjs

# This workflow runs when code is pushed to `main` (i.e: when a pull request is merged)
on:
push:
branches: [main]

luacmartins marked this conversation as resolved.
Show resolved Hide resolved
jobs:
version:
runs-on: ubuntu-latest

# OSBotify will update the version on `main`, so this check is important to prevent an infinite loop
if: ${{ github.actor != 'OSBotify' }}

steps:
# Running this action ensures that only one instance of this job will run at a time.
# This is important to prevent race conditions when multiple pull requests are merged in quick succession
- uses: softprops/turnstyle@8db075d65b19bf94e6e8687b504db69938dc3c65
luacmartins marked this conversation as resolved.
Show resolved Hide resolved
with:
poll-interval-seconds: 10
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- uses: actions/checkout@v3

- name: Decrypt & Import OSBotify GPG key
run: |
cd .github
gpg --quiet --batch --yes --decrypt --passphrase="$LARGE_SECRET_PASSPHRASE" --output OSBotify-private-key.asc OSBotify-private-key.asc.gpg
gpg --import OSBotify-private-key.asc
env:
LARGE_SECRET_PASSPHRASE: ${{ secrets.LARGE_SECRET_PASSPHRASE }}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just making sure this secret was added to the repo via Ring0?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It wasn't, no. Is there anything you'd be able to point me to with instructions on what Ring0 needs to do exactly?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is an example issue: https://github.com/Expensify/Expensify/issues/288197

LARGE_SECRET_PASSPHRASE is in 1Password, so Ring0 will be able to find it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, thanks. I opened this issue to have them added: https://github.com/Expensify/Expensify/issues/302806


- name: Set up git for OSBotify
run: |
git config --global user.signingkey 367811D53E34168C
git config --global commit.gpgsign true
git config --global user.name OSBotify
git config --global user.email infra+osbotify@expensify.com

- uses: actions/setup-node@v3
with:
node-version: '16.x'
registry-url: 'https://registry.npmjs.org'

- name: Generate branch name
run: echo "BRANCH_NAME=OSBotify-bump-version-$(uuidgen)" >> $GITHUB_ENV

- name: Create branch for version-bump pull request
run: git checkout -b ${{ env.BRANCH_NAME }}

- name: Install npm packages
run: npm ci

- name: Update npm version
run: npm version patch

- name: Set new version in GitHub ENV
run: echo "NEW_VERSION=$(jq '.version' package.json)" >> $GITHUB_ENV

- name: Push branch and publish tags
run: git push --set-upstream origin ${{ env.BRANCH_NAME }} && git push --tags

- name: Create pull request
run: |
gh pr create \
--title "Update version to ${{ env.NEW_VERSION }}" \
--body "Update version to ${{ env.NEW_VERSION }}"
sleep 5
env:
GITHUB_TOKEN: ${{ secrets.OS_BOTIFY_TOKEN }}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This secret too?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1


- name: Auto-approve pull request
run: gh pr review --approve ${{ env.BRANCH_NAME }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Auto-merge pull request
run: gh pr merge --merge --delete-branch ${{ env.BRANCH_NAME }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Build package
run: npm run build

- name: Publish to npm
run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}