Skip to content

Commit 0255e5b

Browse files
authored
Workflow to release midstream plugin (#10)
* Fix build (#59) Signed-off-by: Ali Ok <[email protected]> (cherry picked from commit 918c58f) * Workflow to release midstream plugin Signed-off-by: Ali Ok <[email protected]> * Workflow to release midstream plugin Signed-off-by: Ali Ok <[email protected]> * Workflow to release midstream plugin Signed-off-by: Ali Ok <[email protected]> * Address some comments Signed-off-by: Ali Ok <[email protected]> * Hacks to increment patch version Signed-off-by: Ali Ok <[email protected]> * Install specific go version Signed-off-by: Ali Ok <[email protected]> --------- Signed-off-by: Ali Ok <[email protected]>
1 parent 5d0565d commit 0255e5b

File tree

5 files changed

+174
-33
lines changed

5 files changed

+174
-33
lines changed
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
name: Backstage knative-event-mesh-backend
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- 'release-*'
7+
paths:
8+
- 'backstage/plugins/knative-event-mesh-backend/**'
9+
push:
10+
branches:
11+
- 'release-*'
12+
paths:
13+
- 'backstage/plugins/knative-event-mesh-backend/**'
14+
15+
jobs:
16+
release:
17+
name: Release
18+
runs-on: ubuntu-latest
19+
permissions:
20+
contents: read
21+
packages: write # allow GITHUB_TOKEN to publish packages
22+
23+
steps:
24+
- name: Checkout
25+
uses: actions/checkout@v4
26+
27+
- name: Setup Golang
28+
uses: actions/setup-go@v5
29+
with:
30+
go-version: '>=1.21.1' # from https://github.com/openshift-knative/hack/blob/main/go.mod#L3
31+
32+
- name: Setup release name for release branch push
33+
if: github.event_name == 'push'
34+
run: |
35+
BRANCH=$(git rev-parse --abbrev-ref HEAD) #e.g. release-v1.33
36+
echo "Release branch: ${BRANCH}"
37+
GO111MODULE=off go get -u github.com/openshift-knative/hack/cmd/sobranch
38+
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"
39+
# SO_RELEASE_NAME will be something like "release-1.33"
40+
echo "SO_RELEASE_NAME: ${SO_RELEASE_NAME}"
41+
# split the release name to get the version number
42+
## e.g. release-1.33 -> 1.33
43+
BASE_RELEASE_VERSION=${SO_RELEASE_NAME#*-}
44+
echo "BASE_RELEASE_VERSION: ${BASE_RELEASE_VERSION}"
45+
46+
RELEASE_NAME="${BASE_RELEASE_VERSION}.0"
47+
48+
# get the patch release versions for the BASE_RELEASE_VERSION
49+
# if there's one already, increase its number by 1
50+
PATCH_RELEASES=$(npm view @openshift-knative/plugin-knative-event-mesh-backend versions --json | grep ${BASE_RELEASE_VERSION})
51+
echo "Existing PATCH_RELEASES: ${PATCH_RELEASES}"
52+
if [ -z "${PATCH_RELEASES}" ]; then
53+
echo "No existing PATCH_RELEASES found for ${BASE_RELEASE_VERSION}"
54+
else
55+
echo "Existing PATCH_RELEASES found for ${BASE_RELEASE_VERSION}"
56+
PATCH=$(echo "${PATCH_RELEASES}" | tail -1 | tr -d '"' | awk -F \. '{print $3+1}')
57+
RELEASE_NAME="${BASE_RELEASE_VERSION}.${PATCH}"
58+
fi
59+
60+
echo "RELEASE_NAME: ${RELEASE_NAME}"
61+
echo "RELEASE_NAME=${RELEASE_NAME}" >> $GITHUB_ENV
62+
63+
- name: Setup Node.js
64+
uses: actions/setup-node@v4
65+
with:
66+
node-version-file: 'backstage/.nvmrc'
67+
cache: 'yarn'
68+
cache-dependency-path: 'backstage/yarn.lock'
69+
70+
- name: Print environment
71+
run: |
72+
node --version
73+
yarn --version
74+
75+
- name: Install dependencies
76+
shell: bash
77+
working-directory: ./backstage
78+
run: yarn --prefer-offline --frozen-lockfile
79+
80+
- name: Install tooling
81+
shell: bash
82+
working-directory: ./backstage
83+
run: npm install @backstage/cli -g
84+
85+
- name: Run tests
86+
shell: bash
87+
working-directory: ./backstage
88+
run: |
89+
export PATH="./node_modules/.bin/:$PATH"
90+
yarn test
91+
92+
- name: Build
93+
shell: bash
94+
working-directory: ./backstage
95+
run: |
96+
export PATH="./node_modules/.bin/:$PATH"
97+
yarn tsc
98+
yarn build:all
99+
100+
- name: Update version of knative-event-mesh-backend plugin
101+
if: github.event_name == 'push'
102+
shell: bash
103+
working-directory: ./backstage/plugins/knative-event-mesh-backend
104+
run: |
105+
export PATH="./node_modules/.bin/:$PATH"
106+
yarn version --new-version ${RELEASE_NAME} --no-git-tag-version
107+
108+
- name: Prepack knative-event-mesh-backend plugin
109+
shell: bash
110+
working-directory: ./backstage/plugins/knative-event-mesh-backend
111+
run: |
112+
export PATH="./node_modules/.bin/:$PATH"
113+
yarn prepack
114+
115+
- name: Publish knative-event-mesh-backend plugin
116+
uses: JS-DevTools/npm-publish@v3
117+
if: github.event_name == 'push'
118+
with:
119+
token: ${{ secrets.GITHUB_TOKEN }}
120+
access: public
121+
package: backstage/plugins/knative-event-mesh-backend
122+
registry: "https://npm.pkg.github.com"
123+
tag: latest
124+
125+
- name: Postpack knative-event-mesh-backend plugin
126+
shell: bash
127+
working-directory: ./backstage/plugins/knative-event-mesh-backend
128+
run: |
129+
export PATH="./node_modules/.bin/:$PATH"
130+
yarn postpack

backstage/packages/backend/src/plugins/catalog.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
export default async function createPlugin(
1212
env: PluginEnvironment,
1313
): Promise<Router> {
14-
const builder = await CatalogBuilder.create(env);
14+
const builder = CatalogBuilder.create(env);
1515
builder.addProcessor(new ScaffolderEntitiesProcessor());
1616

1717
const knativeEventMeshProviders = KnativeEventMeshProvider.fromConfig(env.config, {

backstage/plugins/knative-event-mesh-backend/package.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "@knative-extensions/plugin-knative-event-mesh-backend",
2+
"name": "@openshift-knative/plugin-knative-event-mesh-backend",
33
"version": "0.0.0-nightly",
44
"main": "src/index.ts",
55
"types": "src/index.ts",
@@ -13,6 +13,11 @@
1313
"backstage": {
1414
"role": "backend-plugin"
1515
},
16+
"repository": {
17+
"type": "git",
18+
"url": "https://github.com/openshift-knative/backstage-plugins.git",
19+
"directory": "backstage/plugins/knative-event-mesh-backend"
20+
},
1621
"scripts": {
1722
"start": "backstage-cli package start",
1823
"build": "backstage-cli package build",
@@ -27,7 +32,7 @@
2732
"@backstage/backend-tasks": "^0.5.21",
2833
"@backstage/config": "^1.1.1",
2934
"@backstage/plugin-catalog-common": "^1.0.22",
30-
"@backstage/catalog-client": "^1.6.3",
35+
"@backstage/catalog-client": "^1.4.6",
3136
"@backstage/catalog-model": "^1.4.5",
3237
"@backstage/plugin-catalog-node": "^1.11.0",
3338
"@types/express": "*",

backstage/plugins/knative-event-mesh-backend/src/providers/knativeEventMeshProcessor.test.ts

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ describe('KnativeEventMeshProcessor', () => {
4444
entity:ApiEntity;
4545
queries?:Query[];
4646
expectedRelations?:CatalogProcessorRelationResult[];
47-
};
47+
}
4848

4949
const testCases:TestCase[] = [
5050
{
@@ -430,36 +430,38 @@ describe('KnativeEventMeshProcessor', () => {
430430
}
431431
];
432432

433-
test.each(testCases)('Name: %s', async ({name, queries, expectedRelations, entity}) => {
434-
if (queries) {
435-
for (const query of queries) {
436-
const entityQueryResult = {
437-
items: query.queryEntitiesResult.items,
438-
totalItems: query.queryEntitiesResult.items.length,
439-
pageInfo: query.queryEntitiesResult.pageInfo
440-
};
441-
catalogApi.queryEntities.mockReturnValueOnce(Promise.resolve(entityQueryResult));
433+
for (const testCase of testCases) {
434+
test(`Name: ${testCase.name}`, async () => {
435+
if (testCase.queries) {
436+
for (const query of testCase.queries) {
437+
const entityQueryResult = {
438+
items: query.queryEntitiesResult.items,
439+
totalItems: query.queryEntitiesResult.items.length,
440+
pageInfo: query.queryEntitiesResult.pageInfo
441+
};
442+
catalogApi.queryEntities.mockReturnValueOnce(Promise.resolve(entityQueryResult));
443+
}
442444
}
443-
}
444445

445-
const emitFn = jest.fn();
446+
const emitFn = jest.fn();
446447

447-
const output = await processor.preProcessEntity(entity, ({} as any), emitFn, ({} as any), ({} as any));
448+
const output = await processor.preProcessEntity(testCase.entity, ({} as any), emitFn, ({} as any), ({} as any));
448449

449-
expect(emitFn).toHaveBeenCalledTimes(expectedRelations?.length || 0);
450+
expect(emitFn).toHaveBeenCalledTimes(testCase.expectedRelations?.length || 0);
450451

451-
expectedRelations?.forEach((relation, index) => {
452-
expect(emitFn).toHaveBeenNthCalledWith(index + 1, relation);
453-
});
452+
testCase.expectedRelations?.forEach((relation, index) => {
453+
expect(emitFn).toHaveBeenNthCalledWith(index + 1, relation);
454+
});
454455

455-
expect(output).toEqual(entity);
456+
expect(output).toEqual(testCase.entity);
456457

457-
expect(catalogApi.queryEntities).toHaveBeenCalledTimes(queries?.length || 0);
458+
expect(catalogApi.queryEntities).toHaveBeenCalledTimes(testCase.queries?.length || 0);
458459

459-
queries?.forEach(query => {
460-
expect(catalogApi.queryEntities).toHaveBeenCalledWith(query.queryEntitiesRequest);
460+
testCase.queries?.forEach(query => {
461+
expect(catalogApi.queryEntities).toHaveBeenCalledWith(query.queryEntitiesRequest);
462+
});
461463
});
464+
}
462465

463-
});
464466
});
465467
});

backstage/plugins/knative-event-mesh-backend/src/providers/knativeEventMeshProvider.test.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,12 @@ describe('KnativeEventMeshProvider', () => {
116116
}
117117
];
118118

119-
test.each(testCases)('Name: %s', async ({name,input, expected}) => {
120-
const result = provider.buildEventTypeEntity(input);
121-
expect(result).toEqual(expected);
122-
});
119+
for (const testCase of testCases) {
120+
test(`Name: ${testCase.name}`, async () => {
121+
const result = provider.buildEventTypeEntity(testCase.input);
122+
expect(result).toEqual(testCase.expected);
123+
});
124+
}
123125
});
124126

125127
describe('buildBrokerEntity', () => {
@@ -212,10 +214,12 @@ describe('KnativeEventMeshProvider', () => {
212214
}
213215
];
214216

215-
test.each(testCases)('Name: %s', async ({name,input, expected}) => {
216-
const result = provider.buildBrokerEntity(input);
217-
expect(result).toEqual(expected);
218-
});
217+
for (const testCase of testCases) {
218+
test(`Name: ${testCase.name}`, async () => {
219+
const result = provider.buildBrokerEntity(testCase.input);
220+
expect(result).toEqual(testCase.expected);
221+
});
219222

223+
}
220224
});
221225
});

0 commit comments

Comments
 (0)