Skip to content

Commit af6fa40

Browse files
authored
feat: get ready for release (#18136)
* fix: ok * fix: ignore * fix: ok * fix: get sha * fix: ok * fix: ok * fix: ok * fix: error * fix: skip run * fix: ok * fix: merge
1 parent e6d36db commit af6fa40

File tree

10 files changed

+308
-84
lines changed

10 files changed

+308
-84
lines changed

.github/workflows/install.yml

+23-4
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@ jobs:
8787
NX_BASE: ${{ steps.export-sha.outputs.NX_BASE }}
8888
DEPLOY_FEATURE: ${{ steps.set-outputs.outputs.DEPLOY_FEATURE }}
8989
runs-on: arc-runners
90+
permissions:
91+
contents: 'read'
92+
actions: 'read'
9093
steps:
9194
- name: Set outputs
9295
id: set-outputs
@@ -97,8 +100,7 @@ jobs:
97100
- name: checkout
98101
uses: actions/checkout@v4
99102
with:
100-
fetch-depth: 0
101-
103+
fetch-depth: 0
102104
- name: Setup yarn
103105
uses: ./.github/actions/setup-yarn
104106

@@ -111,6 +113,7 @@ jobs:
111113
echo "MAIN_BRANCH=${RAW_REF#refs/heads/}" >> $GITHUB_OUTPUT
112114
echo "MAIN_BRANCH=${RAW_REF#refs/heads/}"
113115
- name: Derive appropriate SHAs
116+
if: ${{ inputs.run_merge_queue == false }}
114117
uses: nrwl/nx-set-shas@v4
115118
with:
116119
main-branch-name: ${{ steps.get-branch.outputs.MAIN_BRANCH }}
@@ -119,6 +122,23 @@ jobs:
119122
id: export-sha
120123
shell: bash
121124
run: |
125+
if [[ "${{ inputs.run_merge_queue }}" == "true" ]]; then
126+
# In merge que we always want to use the last
127+
# commit as head - last commit sha is alway succesful
128+
# since else it won't get merged!
129+
# checkout this PR: https://github.com/nrwl/nx-set-shas/pull/145/files
130+
# when this gets merged we can remove this hack!
131+
#
132+
# If we do not do this we will get the wrong base sha
133+
# :(
134+
export NX_HEAD=${{ github.sha }}
135+
export NX_BASE=$(git rev-parse HEAD^1)
136+
echo NX_HEAD="$NX_HEAD" >> "$GITHUB_OUTPUT"
137+
echo NX_BASE="$NX_BASE" >> "$GITHUB_OUTPUT"
138+
echo HEAD="$NX_HEAD" >> "$GITHUB_ENV"
139+
echo BASE="$NX_BASE" >> "$GITHUB_ENV"
140+
exit 0
141+
fi
122142
echo NX_HEAD="${{ env.NX_HEAD }}" >> "$GITHUB_OUTPUT"
123143
echo NX_BASE="${{ env.NX_BASE }}" >> "$GITHUB_OUTPUT"
124144
# NOTE: we reference BASE and HEAD elsewhere
@@ -137,7 +157,6 @@ jobs:
137157
id: prepare-merge-queue
138158
if: ${{ inputs.run_merge_queue == true }}
139159
run: |
140-
yarn --cwd scripts/ci/docker install
141160
node scripts/ci/docker/generate-tag.mjs
142161
143162
# This is to increase the retention days for our GitHub Actions run events
@@ -147,7 +166,7 @@ jobs:
147166
uses: actions/upload-artifact@b18b1d32f3f31abcdc29dee3f2484801fe7822f4
148167

149168
# Don't run this step locally
150-
if: ${{ !github.event.localrun }}
169+
if: ${{ !github.event.localrun && inputs.run_merge_queue == false }}
151170
with:
152171
name: pr-event
153172
path: event.json

.github/workflows/merge-queue.yml

-2
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ jobs:
9696
uses: ./.github/actions/setup-yarn
9797
- name: Set id for matrix
9898
run: |
99-
yarn --cwd scripts/ci/docker install
10099
node ./scripts/ci/docker/create-id.mjs
101100
- name: load-deps
102101
uses: ./.github/actions/load-deps
@@ -210,7 +209,6 @@ jobs:
210209
env:
211210
JSON_DATA: ${{ steps.read.outputs.result }}
212211
run: |
213-
yarn --cwd scripts/ci/docker install
214212
node scripts/ci/docker/write-data.mjs
215213
- name: Get manifest data
216214
id: manifest

.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ infra/helm/**/*.tgz
1414

1515
# dependencies
1616
node_modules/
17-
scripts/ci/docker/node_modules/
1817
**/.yarn/*
1918
!**/.yarn/patches
2019
!**/.yarn/releases

package.json

+2
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@
6666
"mock": "nx mock"
6767
},
6868
"dependencies": {
69+
"@actions/core": "1.11.1",
70+
"@actions/github": "6.0.0",
6971
"@apollo/client": "3.7.15",
7072
"@apollo/gateway": "2.1.1",
7173
"@apollo/subgraph": "2.1.1",

scripts/ci/docker/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@
1111

1212
#!.yarn/cache
1313
.pnp.*
14+
node_modules

scripts/ci/docker/const.mjs

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

scripts/ci/docker/generate-tag.mjs

+11-3
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
11
// @ts-check
22
import github from '@actions/github'
33
import core from '@actions/core'
4-
import { MAIN_BRANCHES } from './const.mjs';
4+
import { MAIN_BRANCHES, RELEASE_BRANCHES } from './const.mjs';
55

66
const randomTag = createRandomString(16)
77
const context = github.context
88
const eventName = context.eventName
99
const sha = context.payload.pull_request?.head.sha || context.sha
1010

1111
const targetBranch = getTargetBranch()
12+
13+
core.setOutput('SHOULD_RUN_BUILD', JSON.stringify(shouldRun()))
14+
if (!shouldRun()) {
15+
process.exit(0);
16+
}
1217
const typeOfDeployment = getTypeOfDeployment()
1318
const artifactName = getArtifactname()
1419
const tagName = getTagname()
1520

1621
core.setOutput('ARTIFACT_NAME', artifactName)
17-
core.setOutput('SHOULD_RUN_BUILD', JSON.stringify(shouldRun()))
1822
core.setOutput('DOCKER_TAG', tagName)
1923
core.setOutput('GIT_BRANCH', targetBranch)
2024
core.setOutput('GIT_SHA', sha)
@@ -23,11 +27,15 @@ console.info(`Docker tag: ${tagName}`)
2327
console.info(`Git branch: ${targetBranch}`)
2428
console.info(`Git SHA: ${sha}`)
2529

30+
2631
function shouldRun() {
2732
if (eventName === 'merge_group') {
2833
if (MAIN_BRANCHES.includes(targetBranch)) {
2934
return true;
3035
}
36+
if (RELEASE_BRANCHES.includes(targetBranch)) {
37+
return true;
38+
}
3139
}
3240
return false;
3341
}
@@ -79,7 +87,7 @@ function getTypeOfDeployment() {
7987
prod: false,
8088
}
8189
}
82-
if (targetBranch.startsWith('release')) {
90+
if (RELEASE_BRANCHES.includes(targetBranch)) {
8391
return {
8492
dev: false,
8593
prod: true,

scripts/ci/docker/get-data.mjs

+61-64
Original file line numberDiff line numberDiff line change
@@ -4,64 +4,79 @@ 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';
7+
import { MAIN_BRANCHES, RELEASE_BRANCHES } from './const.mjs';
88
import { glob } from 'glob'
99

1010
const context = github.context
1111
const branch = getBranch()
1212
const typeOfDeployment = getTypeOfDeployment()
1313
const sha = context.sha
14-
const name = getArtifactname()
15-
const url = `https://api.github.com/repos/island-is/island.is/actions/artifacts?name=${name}`
1614

1715
const _KEY_HAS_OUTPUT = 'MQ_HAS_OUTPUT'
1816
const _KEY_CHANGED_FILES = 'MQ_CHANGED_FILES'
17+
const changedFiles = []
1918

20-
const GITHUB_TOKEN = process.env.GITHUB_TOKEN
21-
const STAGE_NAME = typeOfDeployment.dev
22-
? 'dev'
23-
: typeOfDeployment.staging
24-
? 'staging'
25-
: typeOfDeployment.prod
26-
? 'prod'
27-
: 'dev'
2819

29-
// Read all manifest files
30-
const _MANIFEST_PATHS = [
31-
'charts/islandis-services',
32-
'charts/judicial-system-services',
33-
'charts/identity-server-services',
34-
]
35-
const files = await glob(
36-
`{${_MANIFEST_PATHS.join(',')}}/**/values.${STAGE_NAME}.yaml`,
37-
)
38-
const changedFiles = []
39-
const IMAGE_OBJECT = {}
40-
for (const file of files) {
41-
const textContent = readFileSync(file, 'utf8')
42-
const yamlContent = await jsyaml.load(textContent)
43-
if (
44-
yamlContent &&
45-
typeof yamlContent === 'object' &&
46-
'image' in yamlContent &&
47-
yamlContent.image &&
48-
typeof yamlContent.image === 'object' &&
49-
'repository' in yamlContent.image
50-
) {
51-
const repository = yamlContent.image.repository
52-
const imageName =
53-
typeof repository == 'string' ? repository.split('/').pop() : ''
54-
IMAGE_OBJECT[imageName] ??= []
55-
IMAGE_OBJECT[imageName].push({
56-
filePath: file,
57-
content: yamlContent,
58-
})
20+
if (typeOfDeployment.dev) {
21+
await prepareManifests('dev');
22+
}
23+
24+
if (typeOfDeployment.staging) {
25+
await prepareManifests('staging');
26+
}
27+
28+
if (typeOfDeployment.prod) {
29+
await prepareManifests('prod');
30+
}
31+
32+
if (changedFiles.length > 0) {
33+
console.log(`Changed files is ${changedFiles.join(',')}`)
34+
core.setOutput(_KEY_HAS_OUTPUT, 'true')
35+
core.setOutput(_KEY_CHANGED_FILES, changedFiles.join(','))
36+
} else {
37+
console.log('No files changed')
38+
core.setOutput(_KEY_HAS_OUTPUT, 'false')
39+
}
40+
41+
async function prepareManifests(STAGE_NAME) {
42+
const IMAGE_OBJECT = {}
43+
44+
// Read all manifest files
45+
const _MANIFEST_PATHS = [
46+
'charts/islandis-services',
47+
'charts/judicial-system-services',
48+
'charts/identity-server-services',
49+
]
50+
const files = await glob(
51+
`{${_MANIFEST_PATHS.join(',')}}/**/values.${STAGE_NAME}.yaml`,
52+
)
53+
for (const file of files) {
54+
const textContent = readFileSync(file, 'utf8')
55+
const yamlContent = await jsyaml.load(textContent)
56+
if (
57+
yamlContent &&
58+
typeof yamlContent === 'object' &&
59+
'image' in yamlContent &&
60+
yamlContent.image &&
61+
typeof yamlContent.image === 'object' &&
62+
'repository' in yamlContent.image
63+
) {
64+
const repository = yamlContent.image.repository
65+
const imageName =
66+
typeof repository == 'string' ? repository.split('/').pop() : ''
67+
IMAGE_OBJECT[imageName] ??= []
68+
IMAGE_OBJECT[imageName].push({
69+
filePath: file,
70+
content: yamlContent,
71+
})
72+
}
5973
}
74+
75+
await parseData(IMAGE_OBJECT)
6076
}
6177

62-
await parseData()
6378

64-
async function parseData() {
79+
async function parseData(IMAGE_OBJECT) {
6580
const fileName = `/tmp/data.json`
6681
if (!fs.existsSync(fileName)) {
6782
process.exit(0)
@@ -85,9 +100,6 @@ async function parseData() {
85100
console.info(`Skipping ${imageName}…`)
86101
}
87102
}
88-
console.log(`Changed files is ${changedFiles.join(',')}`)
89-
core.setOutput(_KEY_HAS_OUTPUT, 'true')
90-
core.setOutput(_KEY_CHANGED_FILES, changedFiles.join(','))
91103
}
92104

93105
function getBranch() {
@@ -105,27 +117,12 @@ function getTypeOfDeployment() {
105117
prod: false,
106118
}
107119
}
108-
if (branch.startsWith('release')) {
120+
if (RELEASE_BRANCHES.includes(branch)) {
109121
return {
110122
dev: false,
111-
staging: false,
123+
staging: true,
112124
prod: true,
113125
}
114126
}
115-
return {
116-
dev: false,
117-
staging: false,
118-
prod: false,
119-
}
120-
}
121-
122-
function getArtifactname() {
123-
if (typeOfDeployment.dev) {
124-
return `main-${sha}`
125-
}
126-
if (typeOfDeployment.prod) {
127-
return `release-${sha}`
128-
}
129-
130-
throw new Error(`Unsupported`)
127+
throw new Error(`Unsupported branch: ${branch}`)
131128
}

scripts/ci/docker/package.json

-8
This file was deleted.

0 commit comments

Comments
 (0)