From 6d300aa6606a51c6cbcec67c780caf947fb39c1e Mon Sep 17 00:00:00 2001 From: Ali Ok Date: Tue, 2 Jan 2024 14:18:28 +0300 Subject: [PATCH] Release setup (#13) * Release setup for backend Signed-off-by: Ali Ok * Release setup for plugins Signed-off-by: Ali Ok * Fix NPM publish Signed-off-by: Ali Ok * Switch plugin `main` version to 0.0.0-nightly Signed-off-by: Ali Ok * Set release version of NPM package to GitHub release name Signed-off-by: Ali Ok * Allow passing release name to the manual workflow dispatch Signed-off-by: Ali Ok --------- Signed-off-by: Ali Ok --- .github/workflows/backstage-release.yaml | 85 +++++++++++++++++++ .github/workflows/backstage-unit-tests.yaml | 9 +- backstage/lerna.json | 2 +- backstage/packages/backend/package.json | 2 +- .../knative-event-mesh-backend/.npmignore | 4 + .../knative-event-mesh-backend/package.json | 4 +- backstage/yarn.lock | 2 +- hack/release.sh | 52 ++++++++++++ test/presubmit-tests.sh | 29 +++++++ 9 files changed, 181 insertions(+), 8 deletions(-) create mode 100644 .github/workflows/backstage-release.yaml create mode 100644 backstage/plugins/knative-event-mesh-backend/.npmignore create mode 100755 hack/release.sh create mode 100755 test/presubmit-tests.sh diff --git a/.github/workflows/backstage-release.yaml b/.github/workflows/backstage-release.yaml new file mode 100644 index 00000000..2f78f48e --- /dev/null +++ b/.github/workflows/backstage-release.yaml @@ -0,0 +1,85 @@ +name: Publish release on NPM + +on: + # When manually triggered + workflow_dispatch: + inputs: + releaseName: + description: 'Release name, e.g. v1.2.3' + required: true + + # When there's a release created + release: + types: [ published ] + +jobs: + publish-release-on-npm: + name: Publish release on NPM + runs-on: ubuntu-latest + + steps: + - name: Setup release name + run: | + if [ -z "${{ github.event.release.name }}" ]; then + echo "RELEASE_NAME=${{ github.event.inputs.releaseName }}" >> $GITHUB_ENV + else + echo "RELEASE_NAME=${{ github.event.release.name }}" >> $GITHUB_ENV + fi + + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version-file: 'backstage/.nvmrc' + cache: 'yarn' + cache-dependency-path: 'backstage/yarn.lock' + + - name: Print environment + run: | + node --version + yarn --version + + - name: Print release name + run: | + echo "Release name: ${RELEASE_NAME}" + + - name: Install dependencies + shell: bash + working-directory: ./backstage + run: yarn --prefer-offline --frozen-lockfile + + - name: Install tooling + shell: bash + working-directory: ./backstage + run: npm install @backstage/cli -g + + - name: Run tests + shell: bash + working-directory: ./backstage + run: | + export PATH="./node_modules/.bin/:$PATH" + yarn test + + - name: Build + shell: bash + working-directory: ./backstage + run: | + export PATH="./node_modules/.bin/:$PATH" + yarn tsc + yarn build + + - name: Update version of knative-event-mesh-backend plugin + shell: bash + working-directory: ./backstage/plugins/knative-event-mesh-backend + run: | + export PATH="./node_modules/.bin/:$PATH" + yarn version --new-version ${RELEASE_NAME} --no-git-tag-version + + - name: Publish knative-event-mesh-backend plugin + uses: JS-DevTools/npm-publish@v2 + with: + token: ${{ secrets.NPM_TOKEN }} + access: public + package: backstage/plugins/knative-event-mesh-backend diff --git a/.github/workflows/backstage-unit-tests.yaml b/.github/workflows/backstage-unit-tests.yaml index e7ac3e7f..eb59a81b 100644 --- a/.github/workflows/backstage-unit-tests.yaml +++ b/.github/workflows/backstage-unit-tests.yaml @@ -1,9 +1,6 @@ name: Backstage unit tests on: - push: - branches: - - main pull_request: branches: - main @@ -12,6 +9,7 @@ jobs: unit-tests: name: Test runs-on: ubuntu-latest + steps: - name: Checkout uses: actions/checkout@v4 @@ -23,6 +21,11 @@ jobs: cache: 'yarn' cache-dependency-path: 'backstage/yarn.lock' + - name: Print environment + run: | + node --version + yarn --version + - name: Install dependencies shell: bash working-directory: ./backstage diff --git a/backstage/lerna.json b/backstage/lerna.json index 529a62fe..8efd55f0 100644 --- a/backstage/lerna.json +++ b/backstage/lerna.json @@ -1,6 +1,6 @@ { "packages": ["packages/*", "plugins/*"], "npmClient": "yarn", - "version": "0.1.0", + "version": "0.0.0-nightly", "$schema": "node_modules/lerna/schemas/lerna-schema.json" } diff --git a/backstage/packages/backend/package.json b/backstage/packages/backend/package.json index ff40e56e..935a797b 100644 --- a/backstage/packages/backend/package.json +++ b/backstage/packages/backend/package.json @@ -36,7 +36,7 @@ "@backstage/plugin-search-backend-module-techdocs": "^0.1.11", "@backstage/plugin-search-backend-node": "^1.2.11", "@backstage/plugin-techdocs-backend": "^1.9.0", - "@knative-extensions/plugin-knative-event-mesh-backend": "^0.1.0", + "@knative-extensions/plugin-knative-event-mesh-backend": "0.0.0-nightly", "app": "link:../app", "better-sqlite3": "^9.0.0", "dockerode": "^3.3.1", diff --git a/backstage/plugins/knative-event-mesh-backend/.npmignore b/backstage/plugins/knative-event-mesh-backend/.npmignore new file mode 100644 index 00000000..7c1133ed --- /dev/null +++ b/backstage/plugins/knative-event-mesh-backend/.npmignore @@ -0,0 +1,4 @@ +# keep this file so that npm doesn't use the .gitignore file +src/ +.eslintrc.js +app-config.yaml diff --git a/backstage/plugins/knative-event-mesh-backend/package.json b/backstage/plugins/knative-event-mesh-backend/package.json index 9893dd64..653f3f48 100644 --- a/backstage/plugins/knative-event-mesh-backend/package.json +++ b/backstage/plugins/knative-event-mesh-backend/package.json @@ -1,10 +1,10 @@ { "name": "@knative-extensions/plugin-knative-event-mesh-backend", - "version": "0.1.0", + "version": "0.0.0-nightly", "main": "src/index.ts", "types": "src/index.ts", "license": "Apache-2.0", - "private": true, + "private": false, "publishConfig": { "access": "public", "main": "dist/index.cjs.js", diff --git a/backstage/yarn.lock b/backstage/yarn.lock index 7eb16aa6..03702f01 100644 --- a/backstage/yarn.lock +++ b/backstage/yarn.lock @@ -7831,7 +7831,7 @@ resolved "https://registry.yarnpkg.com/@types/range-parser/-/range-parser-1.2.7.tgz#50ae4353eaaddc04044279812f52c8c65857dbcb" integrity sha512-hKormJbkJqzQGhziax5PItDUTMAM9uE2XXQmM37dyd4hVM+5aVl7oVxMVUiVQn2oCQFN/LKCZdvSM0pFRqbSmQ== -"@types/react-dom@*", "@types/react-dom@<18.0.0": +"@types/react-dom@*", "@types/react-dom@<18.0.0", "@types/react-dom@^17": version "17.0.25" resolved "https://registry.yarnpkg.com/@types/react-dom/-/react-dom-17.0.25.tgz#e0e5b3571e1069625b3a3da2b279379aa33a0cb5" integrity sha512-urx7A7UxkZQmThYA4So0NelOVjx3V4rNFVJwp0WZlbIK5eM4rNJDiN3R/E9ix0MBh6kAEojk/9YL+Te6D9zHNA== diff --git a/hack/release.sh b/hack/release.sh new file mode 100755 index 00000000..6c47d0c7 --- /dev/null +++ b/hack/release.sh @@ -0,0 +1,52 @@ +#!/usr/bin/env bash + +# Copyright 2023 The Knative Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Documentation about this script and how to use it can be found +# at https://github.com/knative/test-infra/tree/master/ci + +source $(dirname $0)/../vendor/knative.dev/hack/release.sh + +export GO111MODULE=on + +# Yaml files to generate, and the source config dir for them. +declare -A COMPONENTS +COMPONENTS=( + ["eventmesh.yaml"]="backends/config/100-eventmesh" +) +readonly COMPONENTS + +function build_release() { + # Update release labels if this is a tagged release + if [[ -n "${TAG}" ]]; then + echo "Tagged release, updating release labels to app.kubernetes.io/version: \"${TAG}\"" + LABEL_YAML_CMD=(sed -e "s|app.kubernetes.io/version: devel|app.kubernetes.io/version: \"${TAG}\"|") + else + echo "Untagged release, will NOT update release labels" + LABEL_YAML_CMD=(cat) + fi + + local all_yamls=() + for yaml in "${!COMPONENTS[@]}"; do + local config="${COMPONENTS[${yaml}]}" + echo "Building Knative Backstage Backends - ${config}" + ko resolve -j 1 ${KO_FLAGS} -f ${config}/ | "${LABEL_YAML_CMD[@]}" > ${yaml} + all_yamls+=(${yaml}) + done + + ARTIFACTS_TO_PUBLISH="${all_yamls[@]}" +} + +main $@ diff --git a/test/presubmit-tests.sh b/test/presubmit-tests.sh new file mode 100755 index 00000000..93e166ea --- /dev/null +++ b/test/presubmit-tests.sh @@ -0,0 +1,29 @@ +#!/usr/bin/env bash + +# Copyright 2023 The Knative Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# This script runs the presubmit tests; it is started by prow for each PR. +# For convenience, it can also be executed manually. +# Running the script without parameters, or with the --all-tests +# flag, causes all tests to be executed, in the right order. +# Use the flags --build-tests, --unit-tests and --integration-tests +# to run a specific set of tests. + +export GO111MODULE=on +export DISABLE_MD_LINTING=1 + +source $(dirname "$0")/../vendor/knative.dev/hack/presubmit-tests.sh + +main $@