Skip to content

Commit a77f6ff

Browse files
bjw-sburoa
andauthored
ci: Use script to determine apps to build, don't build if no apps changed (#183)
Co-authored-by: Steven Kreitzer <[email protected]>
1 parent f930099 commit a77f6ff

File tree

1 file changed

+43
-11
lines changed

1 file changed

+43
-11
lines changed

.github/workflows/release.yaml

Lines changed: 43 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,52 @@ jobs:
3939
dir_names_max_depth: "1"
4040
path: apps
4141

42+
- name: Setup Node
43+
uses: actions/setup-node@cdca7365b2dadb8aad0a33bc7601856ffabcc48e # v4.3.0
44+
45+
- name: Install required packages
46+
run: npm install yaml
47+
4248
- name: Extract Metadata
4349
id: apps
44-
working-directory: apps
45-
run: |
46-
if [[ "${{ github.event_name }}" != "workflow_dispatch" ]]; then
47-
apps="${{ steps.changed-dirs.outputs.all_changed_and_modified_files }}"
48-
else
49-
apps="${{ inputs.app }}"
50-
fi
51-
apps=$(printf "%s/metadata.yaml\n" ${apps})
52-
apps=$(yq eval-all --indent=0 --output-format=json "[.]" ${apps})
53-
echo "apps=${apps}" >> $GITHUB_OUTPUT
50+
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
51+
with:
52+
script: |
53+
const fs = require('fs');
54+
const yaml = require('yaml');
55+
const cwd = process.cwd();
56+
57+
let input = '';
58+
if (context.eventName == 'workflow_dispatch') {
59+
input = '${{ inputs.app }}';
60+
} else {
61+
input = '${{ steps.changed-dirs.outputs.all_changed_and_modified_files }}';
62+
}
63+
64+
appsToBuild = input.split(' ').filter((v) => v !== '');
65+
66+
let output = [];
67+
appsToBuild.forEach(function(app) {
68+
const metadataPath = `${cwd}/apps/${app}/metadata.yaml`;
69+
if (!fs.existsSync(metadataPath)) {
70+
core.setFailed(`App ${app} does not have a metadata.yaml`);
71+
process.exit(1);
72+
}
73+
74+
metadataContent = fs.readFileSync(metadataPath, {encoding: "utf8"});
75+
metadata = yaml.parse(metadataContent);
76+
77+
output.push(metadata);
78+
});
79+
80+
core.setOutput('apps', output);
81+
82+
console.log('apps:');
83+
console.log(JSON.stringify(output, null, 2));
84+
core.summary.addHeading('Apps to build:').addList(appsToBuild).write()
5485
5586
build:
87+
if: ${{ needs.changed.outputs.apps != '[]' }}
5688
needs: changed
5789
name: Build ${{ matrix.app.name }}
5890
uses: ./.github/workflows/image-build-action.yaml
@@ -70,7 +102,7 @@ jobs:
70102
release: ${{ github.event_name == 'workflow_dispatch' && inputs.release || github.event_name == 'push' }}
71103

72104
status:
73-
if: ${{ always() }}
105+
if: ${{ !cancelled() }}
74106
needs: build
75107
name: Build Success
76108
runs-on: ubuntu-latest

0 commit comments

Comments
 (0)