Skip to content

Commit

Permalink
Merge pull request #206 from monaca/MN-5044
Browse files Browse the repository at this point in the history
chore: Added GitHub Actions for npm publish
  • Loading branch information
as-hirose authored Jun 24, 2024
2 parents d17a1be + e9eda6c commit d8224cc
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 0 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/beta.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Publish beta version to npm

on:
push:
tags:
- '*-beta.*'

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
submodules: 'recursive'

- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '20.x'
registry-url: 'https://registry.npmjs.org'

- name: Install dependencies
run: npm ci

- name: Publish to npm
run: npm publish --tag beta
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
54 changes: 54 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Publish to npm

on:
push:
branches:
- master

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
submodules: 'recursive'

- name: Check if version has been published
id: check_version
run: |
version=$(node -p "require('./package.json').version")
echo "VERSION=$version" >> $GITHUB_ENV
if git rev-parse "$version" >/dev/null 2>&1; then
echo "git_tag_exists=true" >> $GITHUB_ENV
else
echo "git_tag_exists=false" >> $GITHUB_ENV
echo "new_tag=$version" >> $GITHUB_ENV
fi
- name: Create Release
if: env.git_tag_exists == 'false'
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ env.new_tag }}
release_name: Release ${{ env.new_tag }}
draft: false
prerelease: false

- name: Setup Node.js
if: env.git_tag_exists == 'false'
uses: actions/setup-node@v3
with:
node-version: '20.x'
registry-url: 'https://registry.npmjs.org'

- name: Install dependencies
run: npm ci

- name: Publish to npm
if: env.git_tag_exists == 'false'
run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,19 @@ The problem might be in the installation of Node.js. If you installed Node.js th
For more information about managing multiple Node.js versions, refer to this [documentation](https://docs.microsoft.com/en-us/windows/dev-environment/javascript/nodejs-on-windows).
4. Install the Monaca CLI again.
5. The login should be working now.

### GitHub Actions

- submodules are recursively installed by adding the submodules: 'recursive' option.

#### When merged/pushed to master branch

- Get version from package.json
- If version does not exist in GitHub tags
- Tag it
- Run npm publish

#### When tagged as -beta.*

- Run npm publish --beta

0 comments on commit d8224cc

Please sign in to comment.