Skip to content

Commit

Permalink
Workflow to release midstream plugin (#10)
Browse files Browse the repository at this point in the history
* Fix build (#59)

Signed-off-by: Ali Ok <aliok@redhat.com>
(cherry picked from commit 918c58f)

* Workflow to release midstream plugin

Signed-off-by: Ali Ok <aliok@redhat.com>

* Workflow to release midstream plugin

Signed-off-by: Ali Ok <aliok@redhat.com>

* Workflow to release midstream plugin

Signed-off-by: Ali Ok <aliok@redhat.com>

* Address some comments

Signed-off-by: Ali Ok <aliok@redhat.com>

* Hacks to increment patch version

Signed-off-by: Ali Ok <aliok@redhat.com>

* Install specific go version

Signed-off-by: Ali Ok <aliok@redhat.com>

---------

Signed-off-by: Ali Ok <aliok@redhat.com>
  • Loading branch information
aliok authored May 9, 2024
1 parent 5d0565d commit 0255e5b
Show file tree
Hide file tree
Showing 5 changed files with 174 additions and 33 deletions.
130 changes: 130 additions & 0 deletions .github/workflows/release-plugins.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
name: Backstage knative-event-mesh-backend

on:
pull_request:
branches:
- 'release-*'
paths:
- 'backstage/plugins/knative-event-mesh-backend/**'
push:
branches:
- 'release-*'
paths:
- 'backstage/plugins/knative-event-mesh-backend/**'

jobs:
release:
name: Release
runs-on: ubuntu-latest
permissions:
contents: read
packages: write # allow GITHUB_TOKEN to publish packages

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Golang
uses: actions/setup-go@v5
with:
go-version: '>=1.21.1' # from https://github.com/openshift-knative/hack/blob/main/go.mod#L3

- name: Setup release name for release branch push
if: github.event_name == 'push'
run: |
BRANCH=$(git rev-parse --abbrev-ref HEAD) #e.g. release-v1.33
echo "Release branch: ${BRANCH}"
GO111MODULE=off go get -u github.com/openshift-knative/hack/cmd/sobranch
SO_RELEASE_NAME=$( $(go env GOPATH)/bin/sobranch --upstream-version "${BRANCH}") # input format: "release-v1.11" or "release-1.11" or "v1.11" or "1.11"
# SO_RELEASE_NAME will be something like "release-1.33"
echo "SO_RELEASE_NAME: ${SO_RELEASE_NAME}"
# split the release name to get the version number
## e.g. release-1.33 -> 1.33
BASE_RELEASE_VERSION=${SO_RELEASE_NAME#*-}
echo "BASE_RELEASE_VERSION: ${BASE_RELEASE_VERSION}"
RELEASE_NAME="${BASE_RELEASE_VERSION}.0"
# get the patch release versions for the BASE_RELEASE_VERSION
# if there's one already, increase its number by 1
PATCH_RELEASES=$(npm view @openshift-knative/plugin-knative-event-mesh-backend versions --json | grep ${BASE_RELEASE_VERSION})
echo "Existing PATCH_RELEASES: ${PATCH_RELEASES}"
if [ -z "${PATCH_RELEASES}" ]; then
echo "No existing PATCH_RELEASES found for ${BASE_RELEASE_VERSION}"
else
echo "Existing PATCH_RELEASES found for ${BASE_RELEASE_VERSION}"
PATCH=$(echo "${PATCH_RELEASES}" | tail -1 | tr -d '"' | awk -F \. '{print $3+1}')
RELEASE_NAME="${BASE_RELEASE_VERSION}.${PATCH}"
fi
echo "RELEASE_NAME: ${RELEASE_NAME}"
echo "RELEASE_NAME=${RELEASE_NAME}" >> $GITHUB_ENV
- 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: 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:all
- name: Update version of knative-event-mesh-backend plugin
if: github.event_name == 'push'
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: Prepack knative-event-mesh-backend plugin
shell: bash
working-directory: ./backstage/plugins/knative-event-mesh-backend
run: |
export PATH="./node_modules/.bin/:$PATH"
yarn prepack
- name: Publish knative-event-mesh-backend plugin
uses: JS-DevTools/npm-publish@v3
if: github.event_name == 'push'
with:
token: ${{ secrets.GITHUB_TOKEN }}
access: public
package: backstage/plugins/knative-event-mesh-backend
registry: "https://npm.pkg.github.com"
tag: latest

- name: Postpack knative-event-mesh-backend plugin
shell: bash
working-directory: ./backstage/plugins/knative-event-mesh-backend
run: |
export PATH="./node_modules/.bin/:$PATH"
yarn postpack
2 changes: 1 addition & 1 deletion backstage/packages/backend/src/plugins/catalog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
export default async function createPlugin(
env: PluginEnvironment,
): Promise<Router> {
const builder = await CatalogBuilder.create(env);
const builder = CatalogBuilder.create(env);
builder.addProcessor(new ScaffolderEntitiesProcessor());

const knativeEventMeshProviders = KnativeEventMeshProvider.fromConfig(env.config, {
Expand Down
9 changes: 7 additions & 2 deletions backstage/plugins/knative-event-mesh-backend/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@knative-extensions/plugin-knative-event-mesh-backend",
"name": "@openshift-knative/plugin-knative-event-mesh-backend",
"version": "0.0.0-nightly",
"main": "src/index.ts",
"types": "src/index.ts",
Expand All @@ -13,6 +13,11 @@
"backstage": {
"role": "backend-plugin"
},
"repository": {
"type": "git",
"url": "https://github.com/openshift-knative/backstage-plugins.git",
"directory": "backstage/plugins/knative-event-mesh-backend"
},
"scripts": {
"start": "backstage-cli package start",
"build": "backstage-cli package build",
Expand All @@ -27,7 +32,7 @@
"@backstage/backend-tasks": "^0.5.21",
"@backstage/config": "^1.1.1",
"@backstage/plugin-catalog-common": "^1.0.22",
"@backstage/catalog-client": "^1.6.3",
"@backstage/catalog-client": "^1.4.6",
"@backstage/catalog-model": "^1.4.5",
"@backstage/plugin-catalog-node": "^1.11.0",
"@types/express": "*",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ describe('KnativeEventMeshProcessor', () => {
entity:ApiEntity;
queries?:Query[];
expectedRelations?:CatalogProcessorRelationResult[];
};
}

const testCases:TestCase[] = [
{
Expand Down Expand Up @@ -430,36 +430,38 @@ describe('KnativeEventMeshProcessor', () => {
}
];

test.each(testCases)('Name: %s', async ({name, queries, expectedRelations, entity}) => {
if (queries) {
for (const query of queries) {
const entityQueryResult = {
items: query.queryEntitiesResult.items,
totalItems: query.queryEntitiesResult.items.length,
pageInfo: query.queryEntitiesResult.pageInfo
};
catalogApi.queryEntities.mockReturnValueOnce(Promise.resolve(entityQueryResult));
for (const testCase of testCases) {
test(`Name: ${testCase.name}`, async () => {
if (testCase.queries) {
for (const query of testCase.queries) {
const entityQueryResult = {
items: query.queryEntitiesResult.items,
totalItems: query.queryEntitiesResult.items.length,
pageInfo: query.queryEntitiesResult.pageInfo
};
catalogApi.queryEntities.mockReturnValueOnce(Promise.resolve(entityQueryResult));
}
}
}

const emitFn = jest.fn();
const emitFn = jest.fn();

const output = await processor.preProcessEntity(entity, ({} as any), emitFn, ({} as any), ({} as any));
const output = await processor.preProcessEntity(testCase.entity, ({} as any), emitFn, ({} as any), ({} as any));

expect(emitFn).toHaveBeenCalledTimes(expectedRelations?.length || 0);
expect(emitFn).toHaveBeenCalledTimes(testCase.expectedRelations?.length || 0);

expectedRelations?.forEach((relation, index) => {
expect(emitFn).toHaveBeenNthCalledWith(index + 1, relation);
});
testCase.expectedRelations?.forEach((relation, index) => {
expect(emitFn).toHaveBeenNthCalledWith(index + 1, relation);
});

expect(output).toEqual(entity);
expect(output).toEqual(testCase.entity);

expect(catalogApi.queryEntities).toHaveBeenCalledTimes(queries?.length || 0);
expect(catalogApi.queryEntities).toHaveBeenCalledTimes(testCase.queries?.length || 0);

queries?.forEach(query => {
expect(catalogApi.queryEntities).toHaveBeenCalledWith(query.queryEntitiesRequest);
testCase.queries?.forEach(query => {
expect(catalogApi.queryEntities).toHaveBeenCalledWith(query.queryEntitiesRequest);
});
});
}

});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,12 @@ describe('KnativeEventMeshProvider', () => {
}
];

test.each(testCases)('Name: %s', async ({name,input, expected}) => {
const result = provider.buildEventTypeEntity(input);
expect(result).toEqual(expected);
});
for (const testCase of testCases) {
test(`Name: ${testCase.name}`, async () => {
const result = provider.buildEventTypeEntity(testCase.input);
expect(result).toEqual(testCase.expected);
});
}
});

describe('buildBrokerEntity', () => {
Expand Down Expand Up @@ -212,10 +214,12 @@ describe('KnativeEventMeshProvider', () => {
}
];

test.each(testCases)('Name: %s', async ({name,input, expected}) => {
const result = provider.buildBrokerEntity(input);
expect(result).toEqual(expected);
});
for (const testCase of testCases) {
test(`Name: ${testCase.name}`, async () => {
const result = provider.buildBrokerEntity(testCase.input);
expect(result).toEqual(testCase.expected);
});

}
});
});

0 comments on commit 0255e5b

Please sign in to comment.