Skip to content

Commit

Permalink
expand values in rules.exists (#1470)
Browse files Browse the repository at this point in the history
* Add failing test

* expand text for rules:exists

* Fix stuff in build.yml

* Fix

* Fix
  • Loading branch information
firecow authored Jan 19, 2025
1 parent cb5967e commit fb70fc7
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 11 deletions.
20 changes: 10 additions & 10 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,22 @@ env:
jobs:

yamllint:
runs-on: ubuntu-latest
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
- uses: ibiqlik/action-yamllint@v3
with:
strict: true

smoke-test:
runs-on: ubuntu-latest
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '22'
cache: 'npm'
- uses: actions/cache@v4
- uses: actions/cache@v4.2.0
with:
path: ${{ env.PKG_CACHE_PATH }}
key: pkg-cache-${{ matrix.node-version }}
Expand All @@ -41,7 +41,7 @@ jobs:
- run: bin/linux/gitlab-ci-local --help

eslint:
runs-on: ubuntu-latest
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
Expand All @@ -51,7 +51,7 @@ jobs:
- run: npm run lint

unused-deps:
runs-on: ubuntu-latest
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
Expand All @@ -61,26 +61,26 @@ jobs:
- run: npx depcheck --ignores depcheck

jest:
runs-on: ubuntu-latest
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v4.2.2
with:
fetch-depth: 0
- uses: actions/setup-node@v4
- uses: actions/setup-node@v4.1.0
with:
cache: 'npm'
- run: npm ci
- name: Run Tests
run: npm run coverage
- uses: sonarsource/sonarcloud-github-action@v4.0
- uses: sonarsource/sonarcloud-github-action@v4.0.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
if: ${{ env.SONAR_TOKEN != '' }}

code-ql:
name: CodeQL
runs-on: ubuntu-latest
runs-on: ubuntu-24.04
permissions:
actions: read
contents: read
Expand Down
15 changes: 14 additions & 1 deletion src/job.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,10 @@ export class Job {
const predefinedVariables = this._predefinedVariables(opt);
this._variables = {...predefinedVariables, ...this.globalVariables, ...jobVariables, ...matrixVariables, ...fileVariables, ...argvVariables};

// Expand variables in rules:changes
if (this.rules && expandVariables) {
const expanded = Utils.expandVariables(this._variables);

// Expand variables in rules:changes
this.rules.forEach((rule, ruleIdx, rules) => {
const changes = Array.isArray(rule.changes) ? rule.changes : rule.changes?.paths;
if (!changes) {
Expand All @@ -182,6 +183,18 @@ export class Job {
});
rules[ruleIdx].changes = changes;
});

// Expand variables in rules:exists
this.rules.forEach((rule, ruleIdx, rules) => {
const exists = Array.isArray(rule.exists) ? rule.exists : null;
if (!exists) {
return;
}
exists.forEach((exist, existId, exists) => {
exists[existId] = Utils.expandText(exist, expanded);
});
rules[ruleIdx].exists = exists;
});
}

let ruleVariables: {[name: string]: string} | undefined;
Expand Down
10 changes: 10 additions & 0 deletions tests/test-cases/rules-exists/.gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,13 @@ skipped-job-dir-recursive:
rules:
- exists:
- notExistsDir/**/*

variables:
DIR: existsDir/existDirNested

var-expand-test:
script:
- echo "${DIR}/recursive.file successfully found, even though dir value was found via variable"
rules:
- exists:
- ${DIR}/recursive.file
1 change: 1 addition & 0 deletions tests/test-cases/rules-exists/integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ test("rules-exists", async () => {
expect(output).toContain("File Executed!");
expect(output).toContain("Directory Executed!");
expect(output).toContain("Directory Recursive Executed!");
expect(output).toContain("existsDir/existDirNested/recursive.file successfully found, even though dir value was found via variable");
expect(output).not.toContain("File Skipped!");
expect(output).not.toContain("Directory Skipped!");
expect(output).not.toContain("Directory Recursive Skipped!");
Expand Down

0 comments on commit fb70fc7

Please sign in to comment.