Skip to content

Commit fb1fc1f

Browse files
author
Oleksandr Dzhychko
authored
Merge pull request #342 from modelix/build/do-not-update-version-before-publishing
build(ts-model-api): do not change version when running publish task
2 parents 9008ccb + c30e1b9 commit fb1fc1f

File tree

3 files changed

+46
-18
lines changed

3 files changed

+46
-18
lines changed

.github/workflows/publish.yml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,16 @@ jobs:
2929
- name: Use tag as version
3030
run: echo "${GITHUB_REF#refs/*/}" > version.txt
3131
- name: Build and Publish Artifacts
32-
run: ./gradlew --build-cache build publish -PciBuild=true -Partifacts.itemis.cloud.user=${{secrets.ARTIFACTS_ITEMIS_CLOUD_USER}} -Partifacts.itemis.cloud.pw=${{secrets.ARTIFACTS_ITEMIS_CLOUD_PW}} -Pgpr.user=${{ github.actor }} -Pgpr.key=${{ secrets.GITHUB_TOKEN }} -Pgpr.universalkey=${{ secrets.GHP_UNIVERSAL_PUBLISH_TOKEN }}
32+
run: >-
33+
./gradlew --build-cache build publish
34+
-PciBuild=true
35+
-Partifacts.itemis.cloud.user=${{ secrets.ARTIFACTS_ITEMIS_CLOUD_USER }}
36+
-Partifacts.itemis.cloud.pw=${{ secrets.ARTIFACTS_ITEMIS_CLOUD_PW }}
37+
-Pgpr.user=${{ github.actor }}
38+
-Pgpr.key=${{ secrets.GITHUB_TOKEN }}
39+
-Pgpr.universalkey=${{ secrets.GHP_UNIVERSAL_PUBLISH_TOKEN }}
40+
-Porg.gradle.internal.http.connectionTimeout=180000
41+
-Porg.gradle.internal.http.socketTimeout=180000
3342
env:
3443
NODE_AUTH_TOKEN: ${{ secrets.ARTIFACTS_ITEMIS_CLOUD_NPM_TOKEN }}
3544
- name: Set up QEMU

ts-model-api/build.gradle.kts

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
import com.github.gradle.node.npm.task.NpmTask
2-
31
plugins {
42
base
53
alias(libs.plugins.node)
64
alias(libs.plugins.ktlint) apply false
5+
alias(libs.plugins.npm.publish)
76
}
87

9-
tasks.named("npm_run_build") {
8+
val npmRunBuild = tasks.named("npm_run_build") {
109
inputs.dir("src")
1110
inputs.file("package.json")
1211
inputs.file("package-lock.json")
@@ -38,24 +37,49 @@ val patchKotlinExternals = tasks.create("patchKotlinExternals") {
3837
}
3938
}
4039

41-
tasks.named("assemble") {
40+
tasks.assemble {
4241
dependsOn("npm_run_build")
4342
dependsOn("npm_run_generateKotlin")
4443
dependsOn(patchKotlinExternals)
4544
}
4645

47-
tasks.named("npm_run_generateKotlin") {
48-
finalizedBy(patchKotlinExternals)
46+
tasks.check {
47+
dependsOn("npm_run_lint")
4948
}
5049

51-
val updateVersion = tasks.register<NpmTask>("updateVersion") {
52-
args.set(listOf("version", "$version"))
50+
tasks.named("npm_run_generateKotlin") {
51+
finalizedBy(patchKotlinExternals)
5352
}
5453

55-
tasks.named("npm_publish") {
56-
dependsOn(updateVersion)
54+
// To copy the files is a workaround for https://github.com/mpetuska/npm-publish/issues/87
55+
// With `NpmPackage.files` we cannot copy the "dist" directory into `destinationDir`.
56+
// We can only either copy the files from "dist" directly into `destinationDir`
57+
// or copy all files from `projectDir` into `destinationDir`.
58+
val copyBuildTypeScriptForPackaging = tasks.create<Copy>("copyBuildTypeScriptForPackaging") {
59+
dependsOn(npmRunBuild)
60+
from(projectDir)
61+
include("dist")
62+
into(layout.buildDirectory.dir("typeScriptForPackaging"))
5763
}
5864

59-
tasks.named("publish") {
60-
dependsOn("npm_publish")
65+
npmPublish {
66+
registries {
67+
register("itemis-npm-open") {
68+
uri.set("https://artifacts.itemis.cloud/repository/npm-open")
69+
System.getenv("NODE_AUTH_TOKEN").takeIf { !it.isNullOrBlank() }?.let {
70+
authToken.set(it)
71+
}
72+
}
73+
}
74+
packages {
75+
create("js") {
76+
packageJsonTemplateFile.set(projectDir.resolve("package.json"))
77+
packageJson {
78+
version.set("${project.version}")
79+
}
80+
files {
81+
setFrom(copyBuildTypeScriptForPackaging.outputs)
82+
}
83+
}
84+
}
6185
}

ts-model-api/package.json

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
"clean": "shx rm -rf dist/ .*cache *.log",
2929
"lint": "npm run lint:debug -- --config tslint.prod.json",
3030
"lint:debug": "tslint --project tsconfig.json --format stylish",
31-
"prepublishOnly": "npm run lint && npm run build",
3231
"test": "shx echo 'Write your own tests'",
3332
"ts": "tsc",
3433
"watch": "tsc --watch",
@@ -47,9 +46,5 @@
4746
"engines": {
4847
"node": ">= 10.18.1",
4948
"npm": ">= 6.13.4"
50-
},
51-
"publishConfig": {
52-
"access": "public",
53-
"registry": "https://artifacts.itemis.cloud/repository/npm-open/"
5449
}
5550
}

0 commit comments

Comments
 (0)