Skip to content

Commit d2f5d1f

Browse files
authored
Refactor CI for forked repositories - POC (#98)
1 parent e142735 commit d2f5d1f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+4776
-68
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[{*.yml, *.json}]
2+
indent_style = space
3+
indent_size = 2

.github/actions/reports-group/.gitignore

Whitespace-only changes.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
PKG_LIST := node-sdk find load-metadata create codecov-uploader codacy-uploader
2+
TARGETS := configure install build package lint test
3+
4+
define FOR_EACH_PKG
5+
@for PKG in $(PKG_LIST); do \
6+
echo ">>>>>> $(1) \"$$PKG\" Package >>>>>>"; \
7+
$(MAKE) -C $$PKG $(1) || exit 1; \
8+
echo "<<<<<<\n"; \
9+
done
10+
endef
11+
12+
$(TARGETS):
13+
$(call FOR_EACH_PKG,$@)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
.PHONY: install
2+
install:
3+
@echo "Nothing to install !"
4+
5+
.PHONY: build
6+
build:
7+
@echo "Nothing to build !"
8+
9+
.PHONY: package
10+
package:
11+
@echo "Nothing to pack !"
12+
13+
.PHONY: lint
14+
lint:
15+
@echo "Nothing to lint !"
16+
17+
.PHONY: test
18+
test:
19+
@echo "Nothing to test !"
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
name: TODO
2+
description: TODO
3+
4+
inputs:
5+
path:
6+
description: A group directory or a glob pattern in order to find group directories and merge their metadata
7+
required: true
8+
project-token:
9+
description: Codacy project token for the repository
10+
required: true
11+
follow-symbolic-links:
12+
description: |
13+
Indicates whether to follow symbolic links when resolving `path`
14+
default: 'true'
15+
16+
outputs:
17+
groups:
18+
description: TODO
19+
value: ${{ steps.build-outputs.outputs.groups }}
20+
reports:
21+
description: TODO
22+
value: ${{ steps.build-outputs.outputs.reports }}
23+
24+
runs:
25+
using: "composite"
26+
steps:
27+
# Even if an input is marked as "required", an empty value (or no value) may be passed !
28+
- name: Validate inputs
29+
uses: actions/github-script@v7
30+
env:
31+
INPUT_MAP: ${{ toJson(inputs) }}
32+
with:
33+
script: |
34+
return core.group(
35+
'Validate inputs',
36+
async () => Object.entries(JSON.parse(process.env.INPUT_MAP))
37+
.forEach(([key, val]) => {
38+
if (!val.trim()) { throw new Error(`Input required and not supplied: ${name}`); }
39+
})
40+
);
41+
42+
# @TODO move reports-group/load-metadata action to a dedicated repo and remove the checkout
43+
- uses: actions/checkout@v4
44+
with:
45+
path: custom-action-repo
46+
47+
- name: Load groups metadata
48+
id: load-metadata
49+
uses: ./custom-action-repo/.github/actions/reports-group/load-metadata
50+
with:
51+
path: ${{ inputs.path }}
52+
format: string # String in order to concatenate interesting values
53+
glue-string: ',' # Ensure glue string as it's the expected one by the uploader
54+
follow-symbolic-links: ${{ inputs.follow-symbolic-links }}
55+
56+
- name: Build uploader option
57+
id: build-uploader-options
58+
uses: actions/github-script@v7
59+
env:
60+
METADATA: ${{ steps.load-metadata.outputs.metadata }}
61+
with:
62+
script: |
63+
core.info('Build uploader options');
64+
const {METADATA} = process.env;
65+
66+
const metadata = JSON.parse(METADATA);
67+
core.setOutput('coverage-reports', metadata.reportPaths); // Trusted path as it comes from trusted metadata (=from `reports-group/load-metadata`)
68+
69+
- name: Ensure at least one report to upload
70+
if: ${{ '' == steps.build-uploader-options.outputs.coverage-reports }}
71+
uses: actions/github-script@v7
72+
with:
73+
script: |
74+
core.setFailed('Unable to retrieve any report to upload. Something wrong most likely happened !');
75+
76+
- name: Upload to codacy
77+
id: upload
78+
uses: codacy/codacy-coverage-reporter-action@v1
79+
with:
80+
coverage-reports: ${{ steps.build-uploader-options.outputs.coverage-reports }}
81+
project-token: ${{ inputs.project-token }}
82+
83+
- name: Build action outputs
84+
id: build-outputs
85+
uses: actions/github-script@v7
86+
env:
87+
METADATA: ${{ steps.load-metadata.outputs.metadata }}
88+
REPORTS: ${{ steps.build-uploader-options.outputs.coverage-reports }}
89+
with:
90+
script: |
91+
core.info('Build output');
92+
const {REPORTS, METADATA} = process.env;
93+
94+
const metadata = JSON.parse(METADATA);
95+
core.setOutput('groups', metadata.path.split(',').join('\n')); // Trusted path as it comes from trusted metadata (=from `reports-group/load-metadata`)
96+
core.setOutput('reports', REPORTS.split(',').join('\n')); // Trusted path, see `build-uploader-options` step
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
.PHONY: install
2+
install:
3+
@echo "Nothing to install !"
4+
5+
.PHONY: build
6+
build:
7+
@echo "Nothing to build !"
8+
9+
.PHONY: package
10+
package:
11+
@echo "Nothing to pack !"
12+
13+
.PHONY: lint
14+
lint:
15+
@echo "Nothing to lint !"
16+
17+
.PHONY: test
18+
test:
19+
@echo "Nothing to test !"
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
name: TODO
2+
description: TODO
3+
4+
inputs:
5+
path:
6+
description: A group directory or a glob pattern in order to find group directories and merge their metadata
7+
required: true
8+
token:
9+
description: Codecov upload token
10+
required: true
11+
follow-symbolic-links:
12+
description: |
13+
Indicates whether to follow symbolic links when resolving `path`
14+
default: 'true'
15+
16+
outputs:
17+
groups:
18+
description: TODO
19+
value: ${{ steps.build-outputs.outputs.groups }}
20+
name:
21+
description: TODO
22+
value: ${{ steps.build-outputs.outputs.name }}
23+
reports:
24+
description: TODO
25+
value: ${{ steps.build-outputs.outputs.reports }}
26+
flags:
27+
description: TODO
28+
value: ${{ steps.build-outputs.outputs.flags }}
29+
30+
runs:
31+
using: "composite"
32+
steps:
33+
# Even if an input is marked as "required", an empty value (or no value) may be passed !
34+
- name: Validate inputs
35+
uses: actions/github-script@v7
36+
env:
37+
INPUT_MAP: ${{ toJson(inputs) }}
38+
with:
39+
script: |
40+
return core.group(
41+
'Validate inputs',
42+
async () => Object.entries(JSON.parse(process.env.INPUT_MAP))
43+
.forEach(([key, val]) => {
44+
if (!val.trim()) { throw new Error(`Input required and not supplied: ${name}`); }
45+
})
46+
);
47+
48+
# @TODO move reports-group/load-metadata action to a dedicated repo and remove the checkout
49+
- uses: actions/checkout@v4
50+
with:
51+
path: custom-action-repo
52+
53+
- name: Load groups metadata
54+
id: load-metadata
55+
uses: ./custom-action-repo/.github/actions/reports-group/load-metadata
56+
with:
57+
path: ${{ inputs.path }}
58+
format: string # String in order to concatenate interesting values
59+
glue-string: ',' # Ensure glue string as it's the expected one by the uploader
60+
follow-symbolic-links: ${{ inputs.follow-symbolic-links }}
61+
62+
- name: Build uploader option
63+
id: build-uploader-options
64+
uses: actions/github-script@v7
65+
env:
66+
METADATA: ${{ steps.load-metadata.outputs.metadata }}
67+
with:
68+
script: |
69+
core.info('Build uploader options');
70+
const {METADATA} = process.env;
71+
72+
const metadata = JSON.parse(METADATA);
73+
core.setOutput('name', metadata.name);
74+
core.setOutput('files', metadata.reportPaths); // Trusted path as it comes from trusted metadata (=from `reports-group/load-metadata`)
75+
if (metadata.flags.length > 0) {
76+
core.setOutput('flags', metadata.flags);
77+
}
78+
79+
- name: Ensure at least one report to upload
80+
if: ${{ '' == steps.build-uploader-options.outputs.files }}
81+
uses: actions/github-script@v7
82+
with:
83+
script: |
84+
core.setFailed('Unable to retrieve any report to upload. Something wrong most likely happened !');
85+
86+
- name: Upload to codacy
87+
id: upload
88+
uses: codecov/codecov-action@v4
89+
with:
90+
token: ${{ inputs.token }}
91+
name: ${{ steps.build-uploader-options.outputs.name }}
92+
files: ${{ steps.build-uploader-options.outputs.files }}
93+
flags: ${{ steps.build-uploader-options.outputs.flags }}
94+
# underlying CLI behavior
95+
disable_search: true
96+
# GHAction behavior
97+
fail_ci_if_error: true
98+
verbose: ${{ runner.debug == '1' }}
99+
100+
- name: Build action outputs
101+
id: build-outputs
102+
uses: actions/github-script@v7
103+
env:
104+
METADATA: ${{ steps.load-metadata.outputs.metadata }}
105+
REPORT_NAME: ${{ steps.build-uploader-options.outputs.name }}
106+
REPORT_FILES: ${{ steps.build-uploader-options.outputs.files }}
107+
REPORT_FLAGS: ${{ steps.build-uploader-options.outputs.flags }}
108+
with:
109+
script: |
110+
core.info('Build output');
111+
const {REPORT_NAME, REPORT_FILES, REPORT_FLAGS, METADATA} = process.env;
112+
113+
const metadata = JSON.parse(METADATA);
114+
core.setOutput('group', metadata.path.split(',').join('\n')); // Trusted path as it comes from trusted metadata (=from `reports-group/load-metadata`)
115+
core.setOutput('name', REPORT_NAME);
116+
core.setOutput('reports', REPORT_FILES.split(',').join('\n')); // Trusted path, see `build-uploader-options` step
117+
core.setOutput('flags', undefined !== REPORT_FLAGS ? REPORT_FLAGS.split(',').join('\n') : '');
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
dist/** -diff linguist-generated=true
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.yarn
2+
node_modules
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
20

0 commit comments

Comments
 (0)