Skip to content

Commit ba80646

Browse files
Drop js-yaml
It is not available in github runners, so use yq to convert to JSON instead. Issue: ZENKO-5132
1 parent 40306ae commit ba80646

5 files changed

Lines changed: 21 additions & 17 deletions

File tree

.github/actions/create-component-deployments/action.yaml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,13 @@ runs:
6464
cat /tmp/changed-deps.yaml
6565
echo "deps-file=/tmp/changed-deps.yaml" >> "$GITHUB_OUTPUT"
6666
67+
- name: Convert deps.yaml to JSON
68+
id: json
69+
shell: bash
70+
run: |
71+
yq -o=json '${{ steps.filter.outputs.deps-file || inputs.deps-file }}' > /tmp/changed-deps.json
72+
echo "deps-file=/tmp/changed-deps.json" >> "$GITHUB_OUTPUT"
73+
6774
- name: Parse component repos from deps.yaml
6875
id: parse
6976
uses: actions/github-script@v7
@@ -72,7 +79,7 @@ runs:
7279
script: |
7380
const { parseDeps } = require('${{ github.action_path }}/parse-deps.js');
7481
const selfRepo = process.env.GITHUB_REPOSITORY || 'scality/zenko';
75-
const { components, repos } = parseDeps('${{ steps.filter.outputs.deps-file || inputs.deps-file }}', selfRepo);
82+
const { components, repos } = parseDeps('${{ steps.json.outputs.deps-file }}', selfRepo);
7683
7784
if (components.length === 0) {
7885
core.info('No component repos found in deps.yaml');

.github/actions/create-component-deployments/parse-deps.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// @ts-check
22
const fs = require('fs');
3-
const yaml = require('js-yaml');
43

54
/**
65
* Strip @sha256:... digest suffix from a tag.
@@ -14,12 +13,12 @@ function stripDigest(tag) {
1413
/**
1514
* Parse deps.yaml and extract component info for ghcr.io/scality/* images.
1615
*
17-
* @param {string} depsFile - Path to deps.yaml
16+
* @param {string} depsFile - Path to deps JSON file (converted from deps.yaml)
1817
* @param {string} selfRepo - The current repo (org/name) to exclude from results
1918
* @returns {{ components: Array<{repo: string, ref: string, image: string}>, repos: string[] }}
2019
*/
2120
function parseDeps(depsFile, selfRepo) {
22-
const deps = yaml.load(fs.readFileSync(depsFile, 'utf8'));
21+
const deps = JSON.parse(fs.readFileSync(depsFile, 'utf8'));
2322
const seen = new Set();
2423
const components = [];
2524
const normalizedSelfRepo = (selfRepo || '').toLowerCase();

tests/workflows/parse-deps.spec.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
11
import path from 'path';
2+
import fs from 'fs';
3+
import yaml from 'js-yaml';
24

35
const { parseDeps, stripDigest } = require('../../.github/actions/create-component-deployments/parse-deps');
46

5-
const depsFile = path.join(__dirname, '../../solution/deps.yaml');
7+
/** Convert a YAML file to a temporary JSON file (mirrors the yq step in action.yaml). */
8+
function yamlToJson(yamlPath: string): string {
9+
const jsonPath = fs.mkdtempSync(path.join(require('os').tmpdir(), 'deps-')) + '/deps.json';
10+
fs.writeFileSync(jsonPath, JSON.stringify(yaml.load(fs.readFileSync(yamlPath, 'utf8'))));
11+
return jsonPath;
12+
}
13+
14+
const depsFile = yamlToJson(path.join(__dirname, '../../solution/deps.yaml'));
615

716
describe('parseDeps', () => {
817
it('extracts scality components from deps.yaml', () => {
@@ -71,7 +80,7 @@ describe('parseDeps', () => {
7180
});
7281

7382
it('sets empty repo for playground images', () => {
74-
const testDeps = path.join(__dirname, 'test-deps.yaml');
83+
const testDeps = yamlToJson(path.join(__dirname, 'test-deps.yaml'));
7584
const { components } = parseDeps(testDeps, 'scality/zenko');
7685
const playground = components.find((c: { image: string }) => c.image.includes('playground'));
7786

tests/workflows/release.spec.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -381,12 +381,6 @@ test.each([
381381
}
382382
}],
383383
'create-deployments': [{
384-
before: 'Checkout',
385-
mockWith: {
386-
name: 'Install js-yaml globally',
387-
run: 'npm install -g js-yaml ; echo "NODE_PATH=$(npm root -g)" >> "$GITHUB_ENV"'
388-
},
389-
}, {
390384
name: 'Create release deployments',
391385
mockWith: {
392386
with: {

tests/workflows/test-create-component-deployments.yaml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,6 @@ jobs:
1111
test-deployments:
1212
runs-on: ubuntu-latest
1313
steps:
14-
- name: Install js-yaml globally
15-
run: |
16-
npm install -g js-yaml
17-
echo "NODE_PATH=$(npm root -g)" >> "$GITHUB_ENV"
18-
1914
- name: Create component deployments
2015
uses: ./.github/actions/create-component-deployments
2116
with:

0 commit comments

Comments
 (0)