Skip to content

Commit 85f1dc4

Browse files
authored
fix: small fixes (#18127)
1 parent 34dd3cd commit 85f1dc4

File tree

6 files changed

+80
-59
lines changed

6 files changed

+80
-59
lines changed

.github/workflows/install.yml

+3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ on:
1919
value: ${{ jobs.install.outputs.MQ_ARTIFACT_NAME }}
2020
MQ_GIT_BRANCH:
2121
value: ${{ jobs.install.outputs.MQ_GIT_BRANCH }}
22+
MQ_SHOULD_RUN_BUILD:
23+
value: ${{ jobs.install.outputs.MQ_SHOULD_RUN_BUILD}}
2224
TEST_CHUNKS:
2325
value: ${{ jobs.install.outputs.TEST_CHUNKS }}
2426
E2E_CHUNKS:
@@ -74,6 +76,7 @@ jobs:
7476
MQ_DOCKER_TAG: ${{ steps.prepare-merge-queue.outputs.DOCKER_TAG }}
7577
MQ_ARTIFACT_NAME: ${{ steps.prepare-merge-queue.outputs.ARTIFACT_NAME }}
7678
MQ_GIT_BRANCH: ${{ steps.prepare-merge-queue.outputs.GIT_BRANCH }}
79+
MQ_SHOULD_RUN_BUILD: ${{ steps.prepare-merge-queue.outputs.SHOULD_RUN_BUILD }}
7780
LINT_CHUNKS: ${{ steps.lint_projects.outputs.CHUNKS }}
7881
TEST_CHUNKS: ${{ steps.test_projects.outputs.CHUNKS }}
7982
E2E_CHUNKS: ${{ steps.e2e_projects.outputs.CHUNKS }}

.github/workflows/merge-queue.yml

+5
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ jobs:
5454
- prepare
5555
- pre-checks
5656
runs-on: arc-runners
57+
if: ${{ needs.prepare.outputs.MQ_SHOULD_RUN_BUILD == 'true' && needs.prepare.outputs.DOCKER_CHUNKS != '[]' }}
5758
permissions:
5859
actions: read
5960
contents: read
@@ -182,11 +183,15 @@ jobs:
182183
needs:
183184
- docker-build
184185
- prepare
186+
- tests
187+
if: ${{ needs.prepare.outputs.MQ_SHOULD_RUN_BUILD == 'true' && needs.prepare.outputs.DOCKER_CHUNKS != '[]' }}
185188
permissions:
186189
id-token: write
187190
contents: write
188191
runs-on: arc-runners
189192
steps:
193+
- name: Check tests success
194+
run: '[[ ${{ needs.tests.result }} != "failure" ]] || exit 1'
190195
- name: Get docker-build output
191196
uses: cloudposse/github-action-matrix-outputs-read@v1
192197
id: read

scripts/ci/docker/const.mjs

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const MAIN_BRANCHES = ['main', 'mq-docker-pre-main']

scripts/ci/docker/generate-tag.mjs

+68-57
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// @ts-check
22
import github from '@actions/github'
33
import core from '@actions/core'
4+
import { MAIN_BRANCHES } from './const.mjs';
45

56
const randomTag = createRandomString(16)
67
const context = github.context
@@ -13,6 +14,7 @@ const artifactName = getArtifactname()
1314
const tagName = getTagname()
1415

1516
core.setOutput('ARTIFACT_NAME', artifactName)
17+
core.setOutput('SHOULD_RUN_BUILD', JSON.stringify(shouldRun()))
1618
core.setOutput('DOCKER_TAG', tagName)
1719
core.setOutput('GIT_BRANCH', targetBranch)
1820
core.setOutput('GIT_SHA', sha)
@@ -21,82 +23,91 @@ console.info(`Docker tag: ${tagName}`)
2123
console.info(`Git branch: ${targetBranch}`)
2224
console.info(`Git SHA: ${sha}`)
2325

26+
function shouldRun() {
27+
if (eventName === 'merge_group') {
28+
if (MAIN_BRANCHES.includes(targetBranch)) {
29+
return true;
30+
}
31+
}
32+
return false;
33+
}
34+
2435
function getTagname() {
25-
if (eventName === 'pull_request' && context.payload.pull_request?.number) {
26-
throw new Error(`Unsupported event: ${eventName}`)
27-
// return `pr-${context.payload.pull_request.number}-${randomTag}`;
28-
}
29-
if (eventName === 'merge_group') {
30-
const dateString = new Date().toISOString().split('T')[0].replace(/-/g, '')
31-
if (typeOfDeployment.dev) {
32-
return `main_${dateString}_${randomTag}`
36+
if (eventName === 'pull_request' && context.payload.pull_request?.number) {
37+
throw new Error(`Unsupported event: ${eventName}`)
38+
// return `pr-${context.payload.pull_request.number}-${randomTag}`;
3339
}
34-
if (typeOfDeployment.prod) {
35-
return `release_${dateString}_${randomTag}`
40+
if (eventName === 'merge_group') {
41+
const dateString = new Date().toISOString().split('T')[0].replace(/-/g, '')
42+
if (typeOfDeployment.dev) {
43+
return `main_${dateString}_${randomTag}`
44+
}
45+
if (typeOfDeployment.prod) {
46+
return `release_${dateString}_${randomTag}`
47+
}
48+
throw new Error(`Unable to determine artifact name for merge_group event`)
3649
}
37-
throw new Error(`Unable to determine artifact name for merge_group event`)
38-
}
39-
throw new Error(
40-
`Unable to determine artifact name for event type: ${eventName}`,
41-
)
50+
throw new Error(
51+
`Unable to determine artifact name for event type: ${eventName}`,
52+
)
4253
}
4354

4455
function getArtifactname() {
45-
if (eventName === 'pull_request' && context.payload.pull_request?.number) {
46-
throw new Error(`Unsupported event: ${eventName}`)
47-
// return `pr-${context.payload.pull_request.number}`;
48-
}
49-
if (eventName === 'merge_group') {
50-
if (typeOfDeployment.dev) {
51-
return `main-${context.payload.merge_group.head_sha}`
56+
if (eventName === 'pull_request' && context.payload.pull_request?.number) {
57+
throw new Error(`Unsupported event: ${eventName}`)
58+
// return `pr-${context.payload.pull_request.number}`;
5259
}
53-
if (typeOfDeployment.prod) {
54-
return `release-${context.payload.merge_group.head_sha}`
60+
if (eventName === 'merge_group') {
61+
if (typeOfDeployment.dev) {
62+
return `main-${context.payload.merge_group.head_sha}`
63+
}
64+
if (typeOfDeployment.prod) {
65+
return `release-${context.payload.merge_group.head_sha}`
66+
}
67+
throw new Error(`Unable to determine artifact name for merge_group event`)
5568
}
56-
throw new Error(`Unable to determine artifact name for merge_group event`)
57-
}
5869

59-
throw new Error(
60-
`Unable to determine artifact name for event type: ${eventName}`,
61-
)
70+
throw new Error(
71+
`Unable to determine artifact name for event type: ${eventName}`,
72+
)
6273
}
6374

6475
function getTypeOfDeployment() {
65-
if (targetBranch === 'main' || targetBranch === 'mq-docker-pre-main') {
66-
return {
67-
dev: true,
68-
prod: false,
76+
if (MAIN_BRANCHES.includes(targetBranch)) {
77+
return {
78+
dev: true,
79+
prod: false,
80+
}
6981
}
70-
}
71-
if (targetBranch.startsWith('release')) {
72-
return {
73-
dev: false,
74-
prod: true,
82+
if (targetBranch.startsWith('release')) {
83+
return {
84+
dev: false,
85+
prod: true,
86+
}
7587
}
76-
}
77-
// UNKNOWN BRANCH
78-
// console.error(`Unknown branch: ${targetBranch} - not sure how to tag this deployment`);
79-
throw new Error(`Unsupported branch: ${targetBranch}`)
88+
// UNKNOWN BRANCH
89+
// console.error(`Unknown branch: ${targetBranch} - not sure how to tag this deployment`);
90+
throw new Error(`Unsupported branch: ${targetBranch}`)
8091
}
8192

8293
function getTargetBranch() {
83-
if (eventName === 'pull_request' && context.payload?.pull_request?.base.ref) {
84-
return context.payload.pull_request.base.ref
85-
}
86-
if (eventName === 'merge_group') {
87-
return context.payload.merge_group.base_ref.replace('refs/heads/', '')
88-
}
94+
if (eventName === 'pull_request' && context.payload?.pull_request?.base.ref) {
95+
return context.payload.pull_request.base.ref
96+
}
97+
if (eventName === 'merge_group') {
98+
return context.payload.merge_group.base_ref.replace('refs/heads/', '')
99+
}
89100

90-
throw new Error(
91-
`Unable to determine target branch for event type: ${eventName}`,
92-
)
101+
throw new Error(
102+
`Unable to determine target branch for event type: ${eventName}`,
103+
)
93104
}
94105

95106
function createRandomString(length) {
96-
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
97-
let result = ''
98-
for (let i = 0; i < length; i++) {
99-
result += chars.charAt(Math.floor(Math.random() * chars.length))
100-
}
101-
return result
107+
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
108+
let result = ''
109+
for (let i = 0; i < length; i++) {
110+
result += chars.charAt(Math.floor(Math.random() * chars.length))
111+
}
112+
return result
102113
}

scripts/ci/docker/get-data.mjs

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import jsyaml from 'js-yaml'
44
import { execSync } from 'node:child_process'
55
import core from '@actions/core'
66
import github from '@actions/github'
7+
import { MAIN_BRANCHES } from './const.mjs';
78
import { glob } from 'glob'
89

910
const context = github.context
@@ -97,7 +98,7 @@ function getBranch() {
9798
}
9899

99100
function getTypeOfDeployment() {
100-
if (branch === 'main' || branch === 'mq-docker-pre-main') {
101+
if (MAIN_BRANCHES.includes(branch)) {
101102
return {
102103
dev: true,
103104
staging: false,

scripts/tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"extends": "../tsconfig.base.json",
33
"files": [],
4-
"include": ["**/*.ts"]
4+
"include": ["**/*.ts", "ci/docker/const.mjs"]
55
}

0 commit comments

Comments
 (0)