CI: Add a step on main pipelines to temporarily update the package.json v… (#75018)

* Add a step on main pipelines to temporarily update the package.json version to include the build number
This commit is contained in:
Kevin Minehart 2023-09-18 16:53:42 -05:00 committed by GitHub
parent 5caf4e1485
commit c7ef496750
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 61 additions and 16 deletions

View File

@ -526,6 +526,17 @@ steps:
depends_on: []
image: node:18.12.0-alpine
name: yarn-install
- commands:
- apk add --update jq bash
- yarn packages:build
- yarn packages:pack
- ./scripts/validate-npm-packages.sh
depends_on:
- yarn-install
environment:
NODE_OPTIONS: --max_old_space_size=8192
image: node:18.12.0-alpine
name: build-frontend-packages
- commands:
- git clone "https://$${GITHUB_TOKEN}@github.com/grafana/grafana-enterprise.git"
--depth=1
@ -570,17 +581,6 @@ steps:
server: https://drone.grafana.net
token:
from_secret: drone_token
- commands:
- apk add --update jq bash
- yarn packages:build
- yarn packages:pack
- ./scripts/validate-npm-packages.sh
depends_on:
- yarn-install
environment:
NODE_OPTIONS: --max_old_space_size=8192
image: node:18.12.0-alpine
name: build-frontend-packages
- commands:
- /src/grafana-build package --distro=linux/amd64,linux/arm64,linux/arm/v7 --go-version=1.20.8
--yarn-cache=$$YARN_CACHE_FOLDER --build-id=$$DRONE_BUILD_NUMBER --grafana-dir=$$PWD
@ -1710,6 +1710,17 @@ steps:
depends_on: []
image: node:18.12.0-alpine
name: yarn-install
- commands:
- apk add --update jq
- new_version=$(cat package.json | jq .version | sed s/pre/$DRONE_BUILD_NUMBERpre/g)
- 'echo "New version: $new_version"'
- yarn run lerna version $new_version --exact --no-git-tag-version --no-push --force-publish
-y
- yarn install --mode=update-lockfile
depends_on:
- yarn-install
image: node:18.12.0-alpine
name: update-package-json-version
- commands:
- apk add --update jq bash
- yarn packages:build
@ -1717,6 +1728,7 @@ steps:
- ./scripts/validate-npm-packages.sh
depends_on:
- yarn-install
- update-package-json-version
environment:
NODE_OPTIONS: --max_old_space_size=8192
image: node:18.12.0-alpine
@ -4190,6 +4202,6 @@ kind: secret
name: gcr_credentials
---
kind: signature
hmac: 44164d7ef0702adcdbc3e53cb3fb70641b04af709a0d22ec65d7a6f87d4af4d2
hmac: 7c1a3c428fbf63231d5ebc9edafbcc8aed44a516b636aabd4454f2e4483c0672
...

View File

@ -19,6 +19,7 @@ load(
"test_a11y_frontend_step",
"trigger_oss",
"trigger_test_release",
"update_package_json_version",
"upload_cdn_step",
"upload_packages_step",
"verify_gen_cue_step",
@ -46,7 +47,7 @@ def build_e2e(trigger, ver_mode):
Args:
trigger: controls which events can trigger the pipeline execution.
ver_mode: used in the naming of the pipeline.
ver_mode: used in the naming of the pipeline. Either 'pr' or 'main'.
Returns:
Drone pipeline.
@ -68,14 +69,19 @@ def build_e2e(trigger, ver_mode):
if ver_mode == "pr":
build_steps.extend(
[
build_frontend_package_step(),
trigger_test_release(),
enterprise_downstream_step(ver_mode = ver_mode),
],
)
else:
build_steps.extend([
update_package_json_version(),
build_frontend_package_step(depends_on = ["update-package-json-version"]),
])
build_steps.extend(
[
build_frontend_package_step(),
rgm_package_step(distros = "linux/amd64,linux/arm64,linux/arm/v7", file = "packages.txt"),
grafana_server_step(),
e2e_tests_step("dashboards-suite"),

View File

@ -409,9 +409,34 @@ def build_frontend_step():
],
}
def build_frontend_package_step():
def update_package_json_version():
"""Updates the packages/ to use a version that has the build ID in it: 10.0.0pre -> 10.0.0-5432pre
Returns:
Drone step that updates the 'version' key in package.json
"""
return {
"name": "update-package-json-version",
"image": images["node"],
"depends_on": [
"yarn-install",
],
"commands": [
"apk add --update jq",
"new_version=$(cat package.json | jq .version | sed s/pre/$DRONE_BUILD_NUMBERpre/g)",
"echo \"New version: $new_version\"",
"yarn run lerna version $new_version --exact --no-git-tag-version --no-push --force-publish -y",
"yarn install --mode=update-lockfile",
],
}
def build_frontend_package_step(depends_on = []):
"""Build the frontend packages using the Grafana build tool.
Args:
depends_on: a list of step names (strings) that must complete before this step runs.
Returns:
Drone step.
"""
@ -432,7 +457,7 @@ def build_frontend_package_step():
},
"depends_on": [
"yarn-install",
],
] + depends_on,
"commands": cmds,
}
@ -959,6 +984,7 @@ def release_canary_npm_packages_step(trigger = None):
"./scripts/publish-npm-packages.sh --dist-tag 'canary' --registry 'https://registry.npmjs.org'",
],
}
if trigger:
step = dict(
step,
@ -971,6 +997,7 @@ def release_canary_npm_packages_step(trigger = None):
},
),
)
return step
def upload_packages_step(ver_mode, trigger = None):