Feature/4 npm deployment (#15) #13
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 to npm | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
release: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Set up Node.js | |
uses: actions/setup-node@v3 | |
with: | |
node-version: '18' | |
registry-url: 'https://registry.npmjs.org/' | |
- name: Install dependencies | |
run: yarn install | |
- name: Import GPG key | |
env: | |
GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }} | |
run: | | |
mkdir -p ~/.gnupg | |
chmod 700 ~/.gnupg | |
echo "$GPG_PRIVATE_KEY" | gpg --batch --import | |
echo "allow-loopback-pinentry" >> ~/.gnupg/gpg-agent.conf | |
echo "use-agent" >> ~/.gnupg/gpg.conf | |
echo "pinentry-mode loopback" >> ~/.gnupg/gpg.conf | |
gpg-connect-agent reloadagent /bye | |
- name: Configure Git to use GPG | |
run: | | |
GPG_KEY_ID=$(gpg --list-secret-keys --keyid-format LONG | grep 'sec' | awk '{print $2}' | cut -d'/' -f2) | |
echo "GPG_KEY_ID=$GPG_KEY_ID" >> $GITHUB_ENV | |
echo "GPG_TTY=$(tty)" >> $GITHUB_ENV | |
git config --global user.signingkey $GPG_KEY_ID | |
git config --global commit.gpgsign true | |
git config --global gpg.program gpg | |
- name: Bump version | |
id: bump_version | |
run: | | |
NEW_VERSION=$(yarn version --patch --no-git-tag-version | grep 'New version' | awk '{print $NF}') | |
echo "::set-output name=new_version::$NEW_VERSION" | |
- name: Commit version bump | |
env: | |
GPG_TTY: ${{ env.GPG_TTY }} | |
PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }} | |
run: | | |
git config --global user.name 'github-actions' | |
git config --global user.email 'github-actions@github.com' | |
git checkout -b release-branch || git checkout release-branch | |
git pull origin release-branch --rebase | |
git add package.json | |
echo "$PASSPHRASE" | gpg --batch --yes --passphrase-fd 0 --pinentry-mode loopback --sign | |
git commit -S -m "chore(release): ${{ steps.bump_version.outputs.new_version }}" | |
git push origin release-branch --force | |
- name: Create Pull Request | |
id: create_pr | |
uses: peter-evans/create-pull-request@v3 | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
commit-message: 'chore(release): ${{ steps.bump_version.outputs.new_version }}' | |
base: main | |
branch: release-branch | |
title: 'Release ${{ steps.bump_version.outputs.new_version }}' | |
body: 'Automated release of version ${{ steps.bump_version.outputs.new_version }}' | |
- name: Build the project | |
if: github.event_name == 'pull_request' | |
run: yarn build | |
- name: Publish to npm | |
if: github.event_name == 'pull_request' && github.event.pull_request.merged | |
run: yarn publish --non-interactive | |
env: | |
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |