diff --git a/.github/workflows/__test-autobuild-working-dir.yml b/.github/workflows/__test-autobuild-working-dir.yml new file mode 100644 index 0000000000..716628d9e5 --- /dev/null +++ b/.github/workflows/__test-autobuild-working-dir.yml @@ -0,0 +1,67 @@ +# Warning: This file is generated automatically, and should not be modified. +# Instead, please modify the template in the pr-checks directory and run: +# pip install ruamel.yaml && python3 sync.py +# to regenerate this file. + +name: PR Check - Autobuild working directory +env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GO111MODULE: auto +on: + push: + branches: + - main + - v1 + - v2 + pull_request: + types: + - opened + - synchronize + - reopened + - ready_for_review + workflow_dispatch: {} +jobs: + test-autobuild-working-dir: + strategy: + matrix: + include: + - os: ubuntu-latest + version: latest + name: Autobuild working directory + timeout-minutes: 45 + runs-on: ${{ matrix.os }} + steps: + - name: Check out repository + uses: actions/checkout@v3 + - name: Prepare test + id: prepare-test + uses: ./.github/prepare-test + with: + version: ${{ matrix.version }} + - name: Test setup + shell: bash + run: | + # Make sure that Gradle build succeeds in autobuild-dir ... + cp -a ../action/tests/java-repo autobuild-dir + # ... and fails if attempted in the current directory + echo > build.gradle + - uses: ./../action/init + with: + languages: java + tools: ${{ steps.prepare-test.outputs.tools-url }} + - uses: ./../action/autobuild + with: + working-directory: autobuild-dir + - uses: ./../action/analyze + env: + TEST_MODE: true + - name: Check database + shell: bash + run: | + cd "$RUNNER_TEMP/codeql_databases" + if [[ ! -d java ]]; then + echo "Did not find a Java database" + exit 1 + fi + env: + INTERNAL_CODEQL_ACTION_DEBUG_LOC: true diff --git a/CHANGELOG.md b/CHANGELOG.md index 111cc5fe04..368a233f62 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## [UNRELEASED] -No user facing changes. +- Add `working-directory` input to the `autobuild` action. [#1024](https://github.com/github/codeql-action/pull/1024) ## 2.1.8 - 08 Apr 2022 diff --git a/autobuild/action.yml b/autobuild/action.yml index 63b83f932a..a6586e31f9 100644 --- a/autobuild/action.yml +++ b/autobuild/action.yml @@ -6,6 +6,12 @@ inputs: default: ${{ github.token }} matrix: default: ${{ toJson(matrix) }} + working-directory: + description: >- + Run the autobuilder using this path (relative to $GITHUB_WORKSPACE) as + working directory. If this input is not set, the autobuilder runs with + $GITHUB_WORKSPACE as its working directory. + required: false runs: using: 'node16' - main: '../lib/autobuild-action.js' \ No newline at end of file + main: '../lib/autobuild-action.js' diff --git a/lib/autobuild-action.js b/lib/autobuild-action.js index cd767459f6..e471683d09 100644 --- a/lib/autobuild-action.js +++ b/lib/autobuild-action.js @@ -52,6 +52,11 @@ async function run() { } language = (0, autobuild_1.determineAutobuildLanguage)(config, logger); if (language !== undefined) { + const workingDirectory = (0, actions_util_1.getOptionalInput)("working-directory"); + if (workingDirectory) { + logger.info(`Changing autobuilder working directory to ${workingDirectory}`); + process.chdir(workingDirectory); + } await (0, autobuild_1.runAutobuild)(language, config, logger); } } diff --git a/lib/autobuild-action.js.map b/lib/autobuild-action.js.map index 7f9fcc43c6..74c7af4d6d 100644 --- a/lib/autobuild-action.js.map +++ b/lib/autobuild-action.js.map @@ -1 +1 @@ -{"version":3,"file":"autobuild-action.js","sourceRoot":"","sources":["../src/autobuild-action.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,oDAAsC;AAEtC,iDAMwB;AACxB,2CAAuE;AACvE,6DAA+C;AAE/C,uCAA6C;AAC7C,iCAAqD;AAErD,8CAA8C;AAC9C,MAAM,GAAG,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC;AASvC,KAAK,UAAU,yBAAyB,CACtC,SAAe,EACf,YAAsB,EACtB,eAAwB,EACxB,KAAa;IAEb,IAAA,4BAAqB,EAAC,WAAI,CAAC,OAAO,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;IAEjD,MAAM,MAAM,GAAG,IAAA,+BAAgB,EAAC,KAAK,EAAE,eAAe,CAAC,CAAC;IACxD,MAAM,gBAAgB,GAAG,MAAM,IAAA,qCAAsB,E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AG,CAAC,KAAK,CAAC,CAAC;QACnB,MAAM,yBAAyB,CAC7B,SAAS,EACT,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAE,EAC1B,QAAQ,EACR,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAC1D,CAAC;QACF,OAAO;KACR;IAED,MAAM,yBAAyB,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;AACzE,CAAC;AAED,KAAK,UAAU,UAAU;IACvB,IAAI;QACF,MAAM,GAAG,EAAE,CAAC;KACb;IAAC,OAAO,KAAK,EAAE;QACd,IAAI,CAAC,SAAS,CAAC,4BAA4B,KAAK,EAAE,CAAC,CAAC;QACpD,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;KACpB;AACH,CAAC;AAED,KAAK,UAAU,EAAE,CAAC"} \ No newline at end of file +{"version":3,"file":"autobuild-action.js","sourceRoot":"","sources":["../src/autobuild-action.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,oDAAsC;AAEtC,iDAOwB;AACxB,2CAAuE;AACvE,6DAA+C;AAE/C,uCAA6C;AAC7C,iCAAqD;AAErD,8CAA8C;AAC9C,MAAM,GAAG,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC;AASvC,KAAK,UAAU,yBAAyB,CACtC,SAAe,EACf,YAAsB,EACtB,eAAwB,EACxB,KAAa;IAEb,IAAA,4BAAqB,EAAC,WAAI,CAAC,OAAO,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;IAEjD,MAAM,MAAM,GAAG,IAAA,+BAAgB,EAAC,KAAK,EAAE,eAAe,CAAC,CAAC;IACxD,MAAM,gBAAgB,GAAG,MAAM,IAAA,qCAAsB,EACnD,WAAW,EACX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C9C;KACF;IAAC,OAAO,KAAK,EAAE;QACd,IAAI,CAAC,SAAS,CACZ,mIACE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CACvD,EAAE,CACH,CAAC;QACF,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QACnB,MAAM,yBAAyB,CAC7B,SAAS,EACT,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAE,EAC1B,QAAQ,EACR,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAC1D,CAAC;QACF,OAAO;KACR;IAED,MAAM,yBAAyB,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;AACzE,CAAC;AAED,KAAK,UAAU,UAAU;IACvB,IAAI;QACF,MAAM,GAAG,EAAE,CAAC;KACb;IAAC,OAAO,KAAK,EAAE;QACd,IAAI,CAAC,SAAS,CAAC,4BAA4B,KAAK,EAAE,CAAC,CAAC;QACpD,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;KACpB;AACH,CAAC;AAED,KAAK,UAAU,EAAE,CAAC"} \ No newline at end of file diff --git a/pr-checks/checks/test-autobuild-working-dir.yml b/pr-checks/checks/test-autobuild-working-dir.yml new file mode 100644 index 0000000000..8d75c9e31a --- /dev/null +++ b/pr-checks/checks/test-autobuild-working-dir.yml @@ -0,0 +1,30 @@ +name: "Autobuild working directory" +description: "Tests working-directory input of autobuild action" +versions: ["latest"] +os: ["ubuntu-latest"] +steps: + - name: Test setup + shell: bash + run: | + # Make sure that Gradle build succeeds in autobuild-dir ... + cp -a ../action/tests/java-repo autobuild-dir + # ... and fails if attempted in the current directory + echo > build.gradle + - uses: ./../action/init + with: + languages: java + tools: ${{ steps.prepare-test.outputs.tools-url }} + - uses: ./../action/autobuild + with: + working-directory: autobuild-dir + - uses: ./../action/analyze + env: + TEST_MODE: true + - name: Check database + shell: bash + run: | + cd "$RUNNER_TEMP/codeql_databases" + if [[ ! -d java ]]; then + echo "Did not find a Java database" + exit 1 + fi diff --git a/src/autobuild-action.ts b/src/autobuild-action.ts index 1a145c7b27..6280266068 100644 --- a/src/autobuild-action.ts +++ b/src/autobuild-action.ts @@ -3,6 +3,7 @@ import * as core from "@actions/core"; import { createStatusReportBase, getActionsStatus, + getOptionalInput, getTemporaryDirectory, sendStatusReport, StatusReportBase, @@ -71,6 +72,13 @@ async function run() { } language = determineAutobuildLanguage(config, logger); if (language !== undefined) { + const workingDirectory = getOptionalInput("working-directory"); + if (workingDirectory) { + logger.info( + `Changing autobuilder working directory to ${workingDirectory}` + ); + process.chdir(workingDirectory); + } await runAutobuild(language, config, logger); } } catch (error) { diff --git a/tests/java-repo/build.gradle b/tests/java-repo/build.gradle new file mode 100644 index 0000000000..591d77bda1 --- /dev/null +++ b/tests/java-repo/build.gradle @@ -0,0 +1,12 @@ +plugins { + id 'application' +} + +repositories { + mavenCentral() +} + +application { + mainClass = 'Main' +} + diff --git a/tests/java-repo/src/main/java/Main.java b/tests/java-repo/src/main/java/Main.java new file mode 100644 index 0000000000..9c8b016543 --- /dev/null +++ b/tests/java-repo/src/main/java/Main.java @@ -0,0 +1,8 @@ +class Main { + public static void main(String args[]) { + if (true) { + System.out.println("Hello, World!"); + } + } +} +