Commit 73af9119 by Jack Westbrook Committed by GitHub

Build: move canary packages to github (#29411)

* ci: wip - add release next npm package step to pr for testing

* ci: remove unpublish logic and use github for package registry

* chore: refresh drone.yml config

* ci: remove redundant variable

* ci: add missing double quote

* chore: move registry arg to npm script

* chore: refresh drone config

* ci: attempt github registry auth

* build: force lerna registry

* build: remote trailing slash

* build: remove obsolete lerna bootstrap, rename next publish files to canary

* chore: remove release_canary_packages step from pr pipeline

* docs(packages): introduce steps for authenticating with github packages

* refactor: move github registry related commands to shell script

* ci(drone): remove echo commands from canary release step

* docs: add missing backtick

Co-authored-by: Dominik Prokop <dominik.prokop@grafana.com>

Co-authored-by: Dominik Prokop <dominik.prokop@grafana.com>
parent 2efcd11c
...@@ -506,15 +506,13 @@ steps: ...@@ -506,15 +506,13 @@ steps:
- test-backend - test-backend
- test-frontend - test-frontend
- name: release-next-npm-packages - name: release-canary-npm-packages
image: grafana/build-container:1.3.0 image: grafana/build-container:1.3.0
commands: commands:
- ./node_modules/.bin/lerna bootstrap - ./scripts/circle-release-canary-packages.sh
- echo "//registry.npmjs.org/:_authToken=$${NPM_TOKEN}" >> ~/.npmrc
- ./scripts/circle-release-next-packages.sh
environment: environment:
NPM_TOKEN: GITHUB_PACKAGE_TOKEN:
from_secret: npm_token from_secret: github_package_token
depends_on: depends_on:
- end-to-end-tests - end-to-end-tests
......
...@@ -27,7 +27,29 @@ Every commit to master that has changes within the `packages` directory is a sub ...@@ -27,7 +27,29 @@ Every commit to master that has changes within the `packages` directory is a sub
<lerna.json version>-<COMMIT_SHA> <lerna.json version>-<COMMIT_SHA>
``` ```
Automatic prereleases are published under the `canary` dist tag. Automatic prereleases are published under the `canary` dist tag to the [github package registry](https://docs.github.com/en/free-pro-team@latest/packages/publishing-and-managing-packages/about-github-packages).
#### Consuming prereleases
As mentioned above the `canary` releases are published to the Github package registry rather than the NPM registry. If you wish to make use of these prereleases please follow these steps:
1. You must use a personal access token to install packages from Github. To create an access token [click here](https://github.com/settings/tokens) and create a token with the `read:packages` scope. Make a copy of the token.
2. Create / modify your `~/.npmrc` file with the following:
```
@grafana:registry=https://npm.pkg.github.com
//npm.pkg.github.com/:_authToken={INSERT_GH_TOKEN_HERE}
```
3. Update the package.json of your project to use either the `canary` channel or a version of the `canary` channel
```json
// plugin's package.json
{
...
"@grafana/data": "canary"
}
```
### Manual release ### Manual release
......
#!/usr/bin/env bash #!/usr/bin/env bash
set -eo pipefail set -eo pipefail
PACKAGES=(ui toolkit data runtime e2e e2e-selectors)
# shellcheck source=./scripts/helpers/exit-if-fail.sh # shellcheck source=./scripts/helpers/exit-if-fail.sh
source "$(dirname "$0")/helpers/exit-if-fail.sh" source "$(dirname "$0")/helpers/exit-if-fail.sh"
...@@ -13,27 +11,6 @@ function prepare_version_commit () { ...@@ -13,27 +11,6 @@ function prepare_version_commit () {
git commit -am "Version commit" git commit -am "Version commit"
} }
function unpublish_previous_canary () {
_package=$1
echo $'\nUnpublishing previous canary packages'
# dist-tag next to be changed to canary when https://github.com/grafana/grafana/pull/18195 is merged
CURRENT_CANARY=$(npm view @grafana/"${_package}" dist-tags.canary)
if [ -z "${CURRENT_CANARY}" ]; then
echo "@grafana/${_package} - Nothing to unpublish"
else
echo "Unpublish @grafana/${_package}@${CURRENT_CANARY}"
_response=$(npm unpublish @grafana/"${_package}"@"${CURRENT_CANARY}" 2>&1) || (
echo "$_response" | grep "404" || (
# We want to deprecate here, rather than fail and return an non-0 exit code
echo "Unpublish unsuccessful [$?]. Deprecating @grafana/${_package}@${CURRENT_CANARY}"
_response=$(npm deprecate @grafana/"${_package}"@"${CURRENT_CANARY}" "this package has been deprecated" 2>&1) || (
echo "$_response" | grep "404" && return 0
)
)
)
fi
}
# check if there were any changes to packages between current and previous commit # check if there were any changes to packages between current and previous commit
count=$(git diff HEAD~1..HEAD --name-only -- packages | awk '{c++} END {print c}') count=$(git diff HEAD~1..HEAD --name-only -- packages | awk '{c++} END {print c}')
count="1" count="1"
...@@ -43,21 +20,15 @@ else ...@@ -43,21 +20,15 @@ else
echo "Changes detected in ${count} packages" echo "Changes detected in ${count} packages"
echo "Starting to release latest canary version" echo "Starting to release latest canary version"
echo "@grafana:registry=https://npm.pkg.github.com" >> ~/.npmrc
echo "//npm.pkg.github.com/:_authToken=${GITHUB_PACKAGE_TOKEN}" >> ~/.npmrc
# For some reason the --no-git-reset is not working as described so # For some reason the --no-git-reset is not working as described so
# to get lerna to publish the packages we need to do a commit to the # to get lerna to publish the packages we need to do a commit to the
# repository. We will not push this commit to the origin repository. # repository. We will not push this commit to the origin repository.
prepare_version_commit prepare_version_commit
# Frontend packages have already been versioned and built by the
# build-frontend step in drone. We will only unpublish the previous
# canary version and publish the current built version as the new
# latest canary build.
for PACKAGE in "${PACKAGES[@]}"
do
unpublish_previous_canary "$PACKAGE"
done
echo $'\nPublishing packages' echo $'\nPublishing packages'
yarn packages:publishCanary yarn packages:publishCanary --registry https://npm.pkg.github.com
fi fi
...@@ -736,25 +736,23 @@ def mysql_integration_tests_step(): ...@@ -736,25 +736,23 @@ def mysql_integration_tests_step():
], ],
} }
def release_next_npm_packages_step(edition): def release_canary_npm_packages_step(edition):
if edition == 'enterprise': if edition == 'enterprise':
return None return None
return { return {
'name': 'release-next-npm-packages', 'name': 'release-canary-npm-packages',
'image': build_image, 'image': build_image,
'depends_on': [ 'depends_on': [
'end-to-end-tests', 'end-to-end-tests',
], ],
'environment': { 'environment': {
'NPM_TOKEN': { 'GITHUB_PACKAGE_TOKEN': {
'from_secret': 'npm_token', 'from_secret': 'github_package_token',
}, },
}, },
'commands': [ 'commands': [
'./node_modules/.bin/lerna bootstrap', './scripts/circle-release-canary-packages.sh',
'echo "//registry.npmjs.org/:_authToken=$${NPM_TOKEN}" >> ~/.npmrc',
'./scripts/circle-release-next-packages.sh',
], ],
} }
......
...@@ -25,7 +25,7 @@ load( ...@@ -25,7 +25,7 @@ load(
'enterprise_downstream_step', 'enterprise_downstream_step',
'frontend_metrics_step', 'frontend_metrics_step',
'publish_storybook_step', 'publish_storybook_step',
'release_next_npm_packages_step', 'release_canary_npm_packages_step',
'upload_packages_step', 'upload_packages_step',
'deploy_to_kubernetes_step', 'deploy_to_kubernetes_step',
'publish_packages_step', 'publish_packages_step',
...@@ -60,7 +60,7 @@ def get_steps(edition, is_downstream=False): ...@@ -60,7 +60,7 @@ def get_steps(edition, is_downstream=False):
build_docker_images_step(edition=edition, ver_mode=ver_mode, ubuntu=True, publish=publish), build_docker_images_step(edition=edition, ver_mode=ver_mode, ubuntu=True, publish=publish),
postgres_integration_tests_step(), postgres_integration_tests_step(),
mysql_integration_tests_step(), mysql_integration_tests_step(),
release_next_npm_packages_step(edition), release_canary_npm_packages_step(edition),
upload_packages_step(edition=edition, ver_mode=ver_mode, is_downstream=is_downstream), upload_packages_step(edition=edition, ver_mode=ver_mode, is_downstream=is_downstream),
deploy_to_kubernetes_step(edition=edition, is_downstream=is_downstream), deploy_to_kubernetes_step(edition=edition, is_downstream=is_downstream),
] ]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment