Skip to content
This repository has been archived by the owner on Nov 6, 2023. It is now read-only.

Commit

Permalink
Dual-scope, dual-distribution automated publishing via GitHub actions (
Browse files Browse the repository at this point in the history
…#91)

* Remove dependency cruft

* Support cross-org publish

* Switch from sed to jq

* Publish to GitHub first due to fragility

* Follow instructions from GitHub support

* Add artifacts

* Re-introduce versioning code

* Fix deprecation warnings

* Enable dual-scope, dual-publish to NPM:@appfolio vs GitHub:@AppFolio-IM

* Clarify cross-org status

* Fix canonical package scope

* Fix artifact download issue

* Remove node version from matrix (Cypress bundles its own)

* Add lint job
  • Loading branch information
xeger authored Jan 3, 2023
1 parent ce1fcfb commit b43e263
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 37 deletions.
1 change: 0 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ module.exports = {
'plugin:cypress/recommended',
'plugin:react/recommended',
// NB: please leave these at the end so they can override all other rules!
'prettier/@typescript-eslint',
'plugin:prettier/recommended'
],
parserOptions: {
Expand Down
77 changes: 54 additions & 23 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,14 @@ on:
types: [published]

jobs:
publish:
name: publish

build:
runs-on: ubuntu-latest

permissions:
contents: read
packages: write

steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 16.x
node-version: 18.x
- run: npm ci
- name: Establish Version
run: |
release='${{ github.event.release.tag_name }}'
Expand All @@ -30,11 +24,59 @@ jobs:
echo "Release name must be in the format of 'vX.Y.Z[-anything]', got '$release'"
exit 1
fi
sed -i -r "s/\"version\": *\".+\"/\"version\": \"$version\"/" package.json
- name: Install Dependencies
run: npm ci
jq --arg version $version '.version = $version' package.json > package.json.tmp && mv package.json.tmp package.json
- name: Build Distributables
run: npm run build
- uses: actions/upload-artifact@v3
with:
name: package.json
path: package.json
- uses: actions/upload-artifact@v3
with:
name: lib
path: lib

publish-github:
needs: build
runs-on: ubuntu-latest
permissions:
packages: write
contents: read
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 18.x
registry-url: https://npm.pkg.github.com/
- uses: actions/download-artifact@v3
with:
name: package.json
- uses: actions/download-artifact@v3
with:
name: lib
path: lib
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}

publish-npmjs:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 18.x
- uses: actions/download-artifact@v3
with:
name: package.json
- uses: actions/download-artifact@v3
with:
name: lib
path: lib
- name: Establish NPM Scope
run: |
jq --arg name '@appfolio/react-gears-cypress' '.name = $name' package.json > package.json.tmp && mv package.json.tmp package.json
- name: Publish to NPM
run: |
touch $HOME/.npmrc
Expand All @@ -46,14 +88,3 @@ jobs:
npm publish
env:
NPM_TOKEN: "${{ secrets.NPM_TOKEN }}"
# - name: Publish to GitHub
# run: |
# touch $HOME/.npmrc
# chmod 0600 $HOME/.npmrc
# cat << EOF > ~/.npmrc
# //npm.pkg.github.com/:_authToken=${GITHUB_TOKEN}
# @appfolio-im:registry=https://npm.pkg.github.com/
# EOF
# npm publish
# env:
# GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
16 changes: 14 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,19 @@ on:
pull_request:

jobs:
lint:
name: lint

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 18.x
- run: npm ci
- run: npm run lint

test:
name: test

Expand All @@ -15,13 +28,12 @@ jobs:
strategy:
matrix:
cypress-version: ["11", "12"]
node-version: ["16.x", "18.x"]

steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
node-version: 18.x
- run: npm ci
- run: npm install --save=false cypress@${{ matrix.cypress-version }}
- run: npm test
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@ Cypress. It provides "finder" functions for finding `react-gears` components
in the DOM, Cypress commands for interacting with compomnents, and some fuzzy
text-matching functions to promote more reliable tests.

**NOTE:** due to historical precedent and the limitations of GitHub packages, this
package is confusingly published to two _different_ NPM scope names depending on the repository.
* Via npmjs.com, it is `@appfolio/react-gears-cypress`
* Via `npm.pkg.github.com`, it is `@appfolio-im/react-gears-cypress`

The package contents are identical for a given version; the only difference is the distribution
mechanism.
Clients should choose a distribution repository and use the suitable corresponding scope name.
In the long run we hope to move this repository back to the `@appfolio` org and unify the scopes.

# How do I use it?

Install the commands at startup by adding a few lines to `cypress/support/commands.js`:
Expand Down
18 changes: 9 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@appfolio/react-gears-cypress",
"name": "@appfolio-im/react-gears-cypress",
"version": "0.0.0",
"packageManager": "[email protected]",
"license": "MIT",
Expand Down Expand Up @@ -51,7 +51,7 @@
"prettier": "^2.8.1",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"typescript": "< 4.10.0",
"typescript": "< 4.9.0",
"webpack": "^5.75.0"
},
"dependencies": {
Expand Down

0 comments on commit b43e263

Please sign in to comment.