Skip to content

Commit baf90d1

Browse files
authored
Merge pull request #1024 from cklin/autobuild-working-dir
autobuild: add working-directory input
2 parents 2d80fe8 + 6f17408 commit baf90d1

File tree

9 files changed

+139
-3
lines changed

9 files changed

+139
-3
lines changed

.github/workflows/__test-autobuild-working-dir.yml

+67
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## [UNRELEASED]
44

5-
No user facing changes.
5+
- Add `working-directory` input to the `autobuild` action. [#1024](https://github.com/github/codeql-action/pull/1024)
66

77
## 2.1.8 - 08 Apr 2022
88

autobuild/action.yml

+7-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ inputs:
66
default: ${{ github.token }}
77
matrix:
88
default: ${{ toJson(matrix) }}
9+
working-directory:
10+
description: >-
11+
Run the autobuilder using this path (relative to $GITHUB_WORKSPACE) as
12+
working directory. If this input is not set, the autobuilder runs with
13+
$GITHUB_WORKSPACE as its working directory.
14+
required: false
915
runs:
1016
using: 'node16'
11-
main: '../lib/autobuild-action.js'
17+
main: '../lib/autobuild-action.js'

lib/autobuild-action.js

+5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/autobuild-action.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: "Autobuild working directory"
2+
description: "Tests working-directory input of autobuild action"
3+
versions: ["latest"]
4+
os: ["ubuntu-latest"]
5+
steps:
6+
- name: Test setup
7+
shell: bash
8+
run: |
9+
# Make sure that Gradle build succeeds in autobuild-dir ...
10+
cp -a ../action/tests/java-repo autobuild-dir
11+
# ... and fails if attempted in the current directory
12+
echo > build.gradle
13+
- uses: ./../action/init
14+
with:
15+
languages: java
16+
tools: ${{ steps.prepare-test.outputs.tools-url }}
17+
- uses: ./../action/autobuild
18+
with:
19+
working-directory: autobuild-dir
20+
- uses: ./../action/analyze
21+
env:
22+
TEST_MODE: true
23+
- name: Check database
24+
shell: bash
25+
run: |
26+
cd "$RUNNER_TEMP/codeql_databases"
27+
if [[ ! -d java ]]; then
28+
echo "Did not find a Java database"
29+
exit 1
30+
fi

src/autobuild-action.ts

+8
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as core from "@actions/core";
33
import {
44
createStatusReportBase,
55
getActionsStatus,
6+
getOptionalInput,
67
getTemporaryDirectory,
78
sendStatusReport,
89
StatusReportBase,
@@ -71,6 +72,13 @@ async function run() {
7172
}
7273
language = determineAutobuildLanguage(config, logger);
7374
if (language !== undefined) {
75+
const workingDirectory = getOptionalInput("working-directory");
76+
if (workingDirectory) {
77+
logger.info(
78+
`Changing autobuilder working directory to ${workingDirectory}`
79+
);
80+
process.chdir(workingDirectory);
81+
}
7482
await runAutobuild(language, config, logger);
7583
}
7684
} catch (error) {

tests/java-repo/build.gradle

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
plugins {
2+
id 'application'
3+
}
4+
5+
repositories {
6+
mavenCentral()
7+
}
8+
9+
application {
10+
mainClass = 'Main'
11+
}
12+
+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
class Main {
2+
public static void main(String args[]) {
3+
if (true) {
4+
System.out.println("Hello, World!");
5+
}
6+
}
7+
}
8+

0 commit comments

Comments
 (0)