Skip to content

Commit a217d13

Browse files
authored
HOTFIX: fix error in pipeline and dockerfile (#59)
* UPD: update CD workflow * UPD: update CI Workflow * ADD: add pipeline to delete old merged and unmerged branches except main * ADD: add pipeline to delete new branches after merge * DEL: delete file * UPD: install new packages * FIX: CI Workflow * ADD: add jest config for tests * FIX: CI Workflow * FIX: use node v20.x only for ci workflow
1 parent d600265 commit a217d13

File tree

11 files changed

+40443
-25898
lines changed

11 files changed

+40443
-25898
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Automatically delete merged branches on PR merge
2+
3+
on:
4+
pull_request:
5+
types:
6+
- closed
7+
8+
permissions:
9+
contents: write
10+
pull-requests: write
11+
12+
jobs:
13+
delete-merged-branches:
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- name: Checkout code
18+
uses: actions/checkout@v4
19+
20+
- name: Delete Branch after merge (Except main)
21+
run: |
22+
BRANCH_NAME=${{ github.event.pull_request.head.ref }}
23+
24+
# Prevent deletion of the main branch
25+
if [ "${{ github.event.pull_request.merged }}" == "true" ] && [ "$BRANCH_NAME" != "main" ]; then
26+
echo "Deleting merged branch: $BRANCH_NAME"
27+
git push origin --delete $BRANCH_NAME
28+
else
29+
echo "Branch not deleted. Either it was not merged or it was 'main'."
30+
env:
31+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/cd-workflow.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11

22
name: Deploy backstage
33
on:
4-
workflow_dispatch:
5-
push:
6-
branches:
7-
- main
4+
workflow_run:
5+
workflows: ["CI Workflow"]
6+
types:
7+
- completed
88

99
jobs:
1010
create-and-push-image:

.github/workflows/ci-workflow.yaml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,30 @@ jobs:
1313
runs-on: ubuntu-latest
1414
strategy:
1515
matrix:
16-
node-version: ['20.x', '22.x']
16+
node-version: ['20.x']
1717

1818
steps:
1919
- uses: actions/checkout@v4
2020
with:
2121
fetch-depth: 0
2222

23+
- name: Enable Corepack
24+
run: corepack enable
25+
26+
- name: Set Yarn Version
27+
run: corepack prepare [email protected] --activate
28+
2329
- name: Set up Node.js
2430
uses: actions/setup-node@v4
2531
with:
2632
node-version: ${{ matrix.node-version }}
27-
cache: 'yarn'
33+
cache: 'yarn'
2834

2935
- name: Check Node.js version
3036
run: node -v
3137

3238
- name: Install dependencies
33-
run: yarn install --frozen-lockfile
39+
run: yarn install
3440

3541
# - name: Lint code
3642
# run: yarn lint:all
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: Delete old merged and unmerged branches
2+
3+
on:
4+
schedule:
5+
- cron: '0 0 * * *' #Run every day at midnight
6+
workflow_dispatch:
7+
8+
permissions:
9+
contents: write
10+
pull-requests: write
11+
12+
jobs:
13+
delete-old-branches:
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- name: Checkout code
18+
uses: actions/checkout@v4
19+
20+
- name: Delete old branches (Except main)
21+
run: |
22+
git fetch --prune
23+
24+
# Delete merged branches older than 30 days, except main
25+
for branch in $(git branch -r --merged | grep -v "main" | grep -v "HEAD"); do
26+
BRANCH_NAME=$(echo $branch | sed 's/origin\///')
27+
LAST_COMMIT_DATE=$(git log -1 --format=%ci $BRANCH_NAME)
28+
DAYS_OLD=$(echo $(( ( $(date +%s) - $(date -d "$LAST_COMMIT_DATE" +%s) ) / 86400 )))
29+
30+
if [[ $DAYS_OLD -gt 30 ]]; then
31+
echo "Deleting merged branch: $BRANCH_NAME"
32+
git push origin --delete $BRANCH_NAME
33+
fi
34+
done
35+
36+
# Delete unmerged branches older than 90 days, except main
37+
for branch in $(git branch -r --no-merged | grep -v "main" | grep -v "HEAD"); do
38+
BRANCH_NAME=$(echo $branch | sed 's/origin\///')
39+
LAST_COMMIT_DATE=$(git log -1 --format=%ci $BRANCH_NAME)
40+
DAYS_OLD=$(echo $(( ( $(date +%s) - $(date -d "$LAST_COMMIT_DATE" +%s) ) / 86400 )))
41+
42+
if [[ $DAYS_OLD -gt 90 ]]; then
43+
echo "Deleting stale unmerged branch: $BRANCH_NAME"
44+
git push origin --delete $BRANCH_NAME
45+
fi
46+
done
47+
env:
48+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/run-tests.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,33 @@ jobs:
99
runs-on: ubuntu-latest
1010
steps:
1111
- uses: actions/checkout@v4
12+
13+
- name: Enable Corepack
14+
run: corepack enable
15+
16+
- name: Set Yarn Version
17+
run: corepack prepare [email protected] --activate
18+
19+
1220
- name: Use Node.js
1321
uses: actions/setup-node@v3
1422
with:
1523
node-version: '20'
24+
1625
- run: yarn install
1726
- run: yarn backstage-cli repo test
1827

1928
run-e2e-tests:
2029
runs-on: ubuntu-latest
2130
steps:
2231
- uses: actions/checkout@v4
32+
33+
- name: Enable Corepack
34+
run: corepack enable
35+
36+
- name: Set Yarn Version
37+
run: corepack prepare [email protected] --activate
38+
2339
- name: Use Node.js
2440
uses: actions/setup-node@v3
2541
with:

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ COPY --chown=node:node examples ./examples
126126

127127

128128
# This switches many Node.js dependencies to production mode. Important APP_ENV and NODE_ENV serve two different purposes
129-
ENV NODE_ENV production
129+
ENV NODE_ENV=production
130130

131131
# This disables node snapshot for Node 20 to work with the Scaffolder
132132
ENV NODE_OPTIONS="--no-node-snapshot"

jest.config.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import type { Config } from 'jest';
2+
3+
const config: Config = {
4+
preset: 'ts-jest',
5+
testEnvironment: 'jsdom',
6+
transform: {
7+
'^.+\\.(ts|tsx)$': 'ts-jest',
8+
'^.+\\.(js|jsx)$': 'babel-jest',
9+
},
10+
transformIgnorePatterns: ['/node_modules/'],
11+
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'],
12+
};
13+
14+
export default config;

package.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,29 @@
4141
]
4242
},
4343
"devDependencies": {
44+
"@babel/core": "^7.26.0",
45+
"@babel/preset-env": "^7.26.0",
4446
"@babel/preset-react": "^7.26.3",
47+
"@babel/preset-typescript": "^7.26.0",
4548
"@backstage/cli": "^0.29.0",
4649
"@backstage/e2e-test-utils": "^0.1.1",
4750
"@playwright/test": "^1.32.3",
4851
"@spotify/prettier-config": "^12.0.0",
52+
"@testing-library/react": "^16.2.0",
53+
"@types/babel__core": "^7",
54+
"@types/babel__preset-env": "^7",
55+
"babel-jest": "^29.7.0",
4956
"canvas": "^2.11.2",
5057
"concurrently": "^8.0.0",
5158
"cross-env": "^7.0.3",
59+
"jest": "^29.7.0",
5260
"jest-canvas-mock": "^2.5.2",
5361
"jsdom": "^24.0.0",
5462
"lerna": "^7.3.0",
5563
"node-gyp": "^10.0.1",
5664
"prettier": "^2.3.2",
65+
"ts-jest": "^29.2.5",
66+
"ts-node": "^10.9.2",
5767
"typescript": "~5.2.0"
5868
},
5969
"resolutions": {

packages/app/src/App.test.tsx

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import React from 'react';
2+
import { render, waitFor } from '@testing-library/react';
3+
import App from './App';
4+
5+
describe('App', () => {
6+
it('should render', async () => {
7+
process.env = {
8+
NODE_ENV: 'test',
9+
APP_CONFIG: [
10+
{
11+
data: {
12+
app: { title: 'Test' },
13+
backend: { baseUrl: 'http://localhost:7007' },
14+
techdocs: {
15+
storageUrl: 'http://localhost:7007/api/techdocs/static/docs',
16+
},
17+
},
18+
context: 'test',
19+
},
20+
] as any,
21+
};
22+
23+
const rendered = render(<App />);
24+
25+
await waitFor(() => {
26+
expect(rendered.baseElement).toBeInTheDocument();
27+
});
28+
});
29+
});

packages/backend/src/soundcheck-programs.yaml

Whitespace-only changes.

0 commit comments

Comments
 (0)