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

Publish NPM beta version on push to main #43

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
15 changes: 13 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ jobs:
run: chmod +x ./gradlew
- name: Test
run: ./gradlew clean allTests

publish:
name: Publish - Nexus
runs-on: ubuntu-latest
needs: unit-test
steps:
Expand All @@ -34,8 +34,19 @@ jobs:
cache: 'gradle'
- name: Change wrapper permission
run: chmod +x ./gradlew
- name: Release Maven package
- uses: actions/setup-node@v1
with:
node-version: 14.x

- name: Release Maven package (snapshot)
run: ./gradlew publishAllPublicationsToSonatypeRepository
env:
OSSRH_USERNAME: ${{ secrets.SONATYPE_OSSRH_USERNAME }}
OSSRH_PASSWORD: ${{ secrets.SONATYPE_OSSRH_PASSWORD }}

- name: Release NPMJS package (beta)
run: |
./gradlew packJsPackage
bash .github/workflows/publish-npmjs-beta.sh
env:
NPMJS_TOKEN: ${{ secrets.NPMJS_TOKEN }}
29 changes: 29 additions & 0 deletions .github/workflows/publish-npmjs-beta.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
set -x

cd build/packages/js || exit

# Set authentication token for npmjs registry
npm set //registry.npmjs.org/:_authToken="$NPMJS_TOKEN"

# Set 'beta' suffix in the version starting with beta.0
sed -i -e 's/-SNAPSHOT"/-beta.0"/g' package.json

# Try to upload the beta version. If it is not available, increase the beta number and try again.
# Iterate a maximum of MAX_ITERATION times.
n=1
MAX_ITERATIONS=30
while [ $n -le $MAX_ITERATIONS ]; do
if ! output=$(npm publish --tag beta 2>&1); then
if [[ "$output" == *"ERR! code E403"* ]]; then
# This error code is likely to be thrown when the version already exists
# Increase beta version number to try again
npm version prerelease
n=$(( n + 1 ))
else
exit 1
fi
else
# If upload is successful, exit
exit 0
fi
done
7 changes: 0 additions & 7 deletions buildSrc/src/main/kotlin/npm-publish-conventions.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ plugins {
id("dev.petuska.npm.publish")
}

val npmjsToken: String? = System.getenv("NPMJS_TOKEN")

project.afterEvaluate {
npmPublish {
access.set(NpmAccess.PUBLIC)
Expand All @@ -32,11 +30,6 @@ project.afterEvaluate {
}
}
}
registries {
npmjs {
authToken.set(npmjsToken)
}
}
}

tasks.named("assembleJsPackage") {
Expand Down