Skip to content

Commit

Permalink
fix publishing configuration, closes #858
Browse files Browse the repository at this point in the history
Co-authored-by: Elliot Winkler <elliot.winkler@gmail.com>
  • Loading branch information
rickycodes and mcmire committed Jul 8, 2022
1 parent b20b44c commit 0d56874
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 10 deletions.
31 changes: 22 additions & 9 deletions .github/workflows/publish-release.yml
Original file line number Diff line number Diff line change
@@ -1,28 +1,31 @@
name: Publish Release

on:
pull_request:
types: [closed]
push:
branches: [main]

jobs:
publish-release:
permissions:
contents: write
if: |
github.event.pull_request.merged == true &&
startsWith(github.event.pull_request.head.ref, 'release/')
# release merge commits come from GitHub user
if: github.event.head_commit.committer.name == 'GitHub'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
ref: ${{ github.sha }}
# we need this commit + the last so we can compare below
fetch-depth: 2
# exit early if the version has not changed
- run: ./scripts/check-version.sh ${{ github.event.before }}
- name: Get Node.js version
id: nvm
run: echo ::set-output name=NODE_VERSION::$(cat .nvmrc)
- uses: actions/setup-node@v2
with:
node-version: ${{ steps.nvm.outputs.NODE_VERSION }}
- uses: MetaMask/action-publish-release@v1
- uses: MetaMask/action-publish-release@v2.0.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- run: |
Expand All @@ -31,7 +34,9 @@ jobs:
- uses: actions/cache@v3
id: restore-build
with:
path: ./dist
path: |
./dist
./node_modules
key: ${{ github.sha }}

publish-npm-dry-run:
Expand All @@ -44,13 +49,17 @@ jobs:
- uses: actions/cache@v3
id: restore-build
with:
path: ./dist
path: |
./dist
./node_modules
key: ${{ github.sha }}
# Set `ignore-scripts` to skip `prepublishOnly` because the release was built already in the previous job
- run: npm config set ignore-scripts true
- name: Dry Run Publish
# omit npm-token token to perform dry run publish
uses: MetaMask/action-npm-publish@v1.1.0
env:
SKIP_PREPACK: true

publish-npm:
environment: npm-publish
Expand All @@ -63,11 +72,15 @@ jobs:
- uses: actions/cache@v3
id: restore-build
with:
path: ./dist
path: |
./dist
./node_modules
key: ${{ github.sha }}
# Set `ignore-scripts` to skip `prepublishOnly` because the release was built already in the previous job
- run: npm config set ignore-scripts true
- name: Publish
uses: MetaMask/action-npm-publish@v1.1.0
with:
npm-token: ${{ secrets.NPM_TOKEN }}
env:
SKIP_PREPACK: true
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"lint:eslint": "eslint . --cache --ext js,ts",
"lint:fix": "yarn lint:eslint --fix && yarn lint:misc --write",
"lint:misc": "prettier '**/*.json' '**/*.md' '!CHANGELOG.md' '**/*.yml' '!.yarnrc.yml' --ignore-path .gitignore",
"prepack": "yarn build",
"prepack": "./scripts/prepack.sh",
"setup": "yarn install",
"test": "jest",
"test:watch": "jest --watch"
Expand Down
19 changes: 19 additions & 0 deletions scripts/check-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env bash

set -x
set -e
set -o pipefail

BEFORE="${1}"

if [[ -z $BEFORE ]]; then
echo "Error: Before SHA not specified."
exit 1
fi

VERSION_BEFORE="$(git show "$BEFORE":package.json | jq --raw-output .version)"
VERSION_AFTER="$(jq --raw-output .version package.json)"
if [[ "$VERSION_BEFORE" == "$VERSION_AFTER" ]]; then
echo "Notice: version unchanged. Skipping release."
exit 1
fi
12 changes: 12 additions & 0 deletions scripts/prepack.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env bash

set -x
set -e
set -o pipefail

if [[ -n $SKIP_PREPACK ]]; then
echo "Notice: skipping prepack."
exit 0
fi

yarn build

0 comments on commit 0d56874

Please sign in to comment.