Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

expand values in rules.exists #1470

Merged
merged 5 commits into from
Jan 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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/[email protected]
- uses: sonarsource/[email protected].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
Loading