This repository has been archived by the owner on Jul 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
143 lines (135 loc) · 5.79 KB
/
detect-workspace-changes.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
name: Detect workspaces changes
on:
workflow_call:
inputs:
from:
required: true
type: string
description: "Current commit SHA"
since:
required: true
type: string
description: "Commit SHA from since the chnages have to be detected"
outputs:
workspaces:
description: "Array of affected workspaces"
value: ${{ jobs.detect_changes.outputs.workspaces }}
toolchains:
description: "Array of affected toolchains workspaces"
value: ${{ jobs.detect_changes.outputs.toolchains }}
extensions:
description: "Array of affected extensions workspaces"
value: ${{ jobs.detect_changes.outputs.extensions }}
libraries:
description: "Array of affected libraries workspaces"
value: ${{ jobs.detect_changes.outputs.libraries }}
packages:
description: "Array of affected packages workspaces"
value: ${{ jobs.detect_changes.outputs.packages }}
jobs:
detect_changes:
runs-on: ubuntu-latest
outputs:
workspaces: ${{ toJson(fromJson(steps.build-array.outputs.result).affectedWorkspaces) }}
toolchains: ${{ toJson(fromJson(steps.build-array.outputs.result).toolchainsWorkspaces) }}
extensions: ${{ toJson(fromJson(steps.build-array.outputs.result).extensionsWorkspaces) }}
libraries: ${{ toJson(fromJson(steps.build-array.outputs.result).librariesWorkspaces) }}
packages: ${{ toJson(fromJson(steps.build-array.outputs.result).packagesWorkspaces) }}
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Checkout to since commit
run: git checkout ${{ inputs.since }}
- name: Checkout to current commit
run: git checkout ${{ inputs.from }}
- uses: actions/setup-node@v3
with:
node-version: '18.16.1'
- name: Setup yarn
id: setup-yarn
# Install yarn 3 & workspace-tools
run: |
corepack enable
corepack prepare yarn@stable --activate
yarn -v
- name: Get yarn workspaces output
id: raw-workspaces-list
run: |
yarn workspaces list --json --since=${{ inputs.since }}
echo "raw-workspaces='$(yarn workspaces list --json --since=${{ inputs.since }} | tr '\n' ' ')'" | tee output.txt >> $GITHUB_OUTPUT
cat output.txt
- name: Build array
id: build-array
uses: actions/github-script@v6
with:
script: |
const rawWorkspacesLines = `${{ steps.raw-workspaces-list.outputs.raw-workspaces }}`
const workspacesLines = rawWorkspacesLines.replace(/'/g, '')
console.log(workspacesLines)
const workspaces = workspacesLines.trim().split(' ').map(line => {
console.log(line)
return JSON.parse(line)
})
console.log(workspaces)
const affectedWorkspaces = workspaces.filter(workspace => {
return workspace.location !== '.'
}).map(workspace => {
return {
name: workspace.name
}
})
console.log(affectedWorkspaces)
const librariesWorkspaces = affectedWorkspaces.filter(workspace => {
return workspace.name.startsWith('@osmium-libs/')
}).map(workspace => ({
name: workspace.name
}))
const packagesWorkspaces = affectedWorkspaces.filter(workspace => {
return workspace.name.startsWith('@osmium-packages/')
}).map(workspace => ({
name: workspace.name
}))
const extensionsWorkspaces = affectedWorkspaces.filter(workspace => {
return workspace.name.match(/^osmium-(?:manager|(?!\w+-\w+)(?:\w+))$/)
}).map(workspace => ({
name: workspace.name
}))
const extensionsFoldersWorkspaces = affectedWorkspaces.filter(workspace => {
return workspace.name.match(/^osmium-\w+-\w+$/)
}).map(workspace => ({
name: workspace.name
}))
const missingExtensionsWorkspaces = extensionsFoldersWorkspaces.map(workspaceFolder => {
const extensionName = workspaceFolder.name.split('-').slice(0, 2).join('-')
const extensionWorkspace = extensionsWorkspaces.find(workspace => {
return workspace.name === extensionName
})
if (!extensionWorkspace) {
return {
name: extensionName
}
}
return extensionWorkspace
})
const completeList = [...extensionsWorkspaces, ...missingExtensionsWorkspaces]
const completeExtensionsWorkspaces = completeList.filter((workspace, index, self) => {
return index === self.findIndex((t) => (
t.name === workspace.name
))
})
return {
affectedWorkspaces,
extensionsWorkspaces: completeExtensionsWorkspaces,
librariesWorkspaces,
packagesWorkspaces
}
- name: debug
run: |
echo "Affected workspaces: ${{ toJson(fromJson(steps.build-array.outputs.result).affectedWorkspaces) }}"
echo "------------------------------------"
echo "Extensions workspaces: ${{ toJson(fromJson(steps.build-array.outputs.result).extensionsWorkspaces) }}"
echo "------------------------------------"
echo "Libraries workspaces: ${{ toJson(fromJson(steps.build-array.outputs.result).librariesWorkspaces) }}"
echo "------------------------------------"
echo "Packages workspaces: ${{ toJson(fromJson(steps.build-array.outputs.result).packagesWorkspaces) }}"