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

Modified GH action to download jar file from release #34

Merged
merged 17 commits into from
Jan 20, 2023
3 changes: 3 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ jobs:
fetch-depth: 0
- name: Integration tests
uses: ./
with:
use-release: "false"
push-to-remote: "false"
buildifier:
runs-on: ubuntu-latest
steps:
Expand Down
29 changes: 26 additions & 3 deletions action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@ inputs:
github-token:
description: "A token for the github repository"
default: ${{ github.token }}
use-release:
description: "Whether to use prebuild jar from release, instead of compiling code"
default: "true"
push-to-remote:
description: "Whether to push changes to remote and open pull requests"
default: "true"
additional-args:
description: "Additional arguments to bazel steward jar"
required: false

runs:
using: "composite"
Expand All @@ -16,11 +25,25 @@ runs:
uses: actions/setup-java@v1
with:
java-version: 11
- name: Download release
if: ${{ inputs.use-release == 'true' }}
run: |
TAG_NAME=$(echo "${{ github.action_path }}" | grep -Po "(?<=\/)[^\/]*$")
gh release download $TAG_NAME --pattern bazel-steward.jar --repo VirtusLab/bazel-steward
env:
GH_TOKEN: ${{ github.token }}
shell: bash
- name: Build jar file
if: ${{ inputs.use-release != 'true' }}
uses: ./.github
- uses: fregante/setup-git-user@v1
- name: Setup git user
uses: fregante/setup-git-user@v1
- name: Run bazel steward
run: java -jar bazel-steward.jar --github
run: java -jar bazel-steward.jar --github ${{ inputs.push-to-remote == 'true' && '--pushToRemote' || '' }} ${{ inputs.additional-args }}
shell: bash
env:
GITHUB_TOKEN: ${{ inputs.github-token }}
GITHUB_TOKEN: ${{ inputs.github-token }}

branding:
icon: 'umbrella'
color: 'green'
19 changes: 16 additions & 3 deletions app/src/main/kotlin/org/virtuslab/bazelsteward/app/Context.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,28 @@ data class Context(
val repository by parser.argument(ArgType.String, description = "Location of the local repository to scan")
.optional().default(".")
val github by parser.option(ArgType.Boolean, description = "Run as a github action").default(false)
val pushToRemote by parser.option(ArgType.Boolean, fullName = "push-to-remote", description = "Push to remote", shortName = "p").default(false)
val pushToRemote by parser.option(
ArgType.Boolean,
description = "Push to remote",
fullName = "push-to-remote",
shortName = "p"
).default(false)
val baseBranch by parser.option(
ArgType.String,
fullName = "base-branch",
description = "Branch that will be set as a base in pull request"
)

parser.parse(args)

val repoPath = if (github) GithubClient.getRepoPath(env) else Path(repository)
val baseBranch = runBlocking {
val baseBranchName = baseBranch ?: runBlocking {
GitClient(repoPath.toFile()).runGitCommand("rev-parse --abbrev-ref HEAD".split(' ')).trim()
}
val config = Config(repoPath, pushToRemote, baseBranch)

val config = Config(repoPath, pushToRemote, baseBranchName)

@Suppress("UNUSED_VARIABLE")
val bsc = runBlocking { BazelStewardConfiguration(repoPath).get() } // will be used later
val bfs = BazelFileSearch(config)
val mde = MavenDataExtractor(config)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ class GitClient(private val repositoryFile: File) {
.onExit().await()
val stdout = process.inputStream.bufferedReader().use { it.readText() }
val stderr = process.errorStream.bufferedReader().use { it.readText() }
if (stderr.isBlank()) stdout else throw RuntimeException(stderr)

if (process.exitValue() == 0) stdout else throw RuntimeException(
"${command.joinToString(" ")}\n$stdout\n$stderr"
)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.virtuslab.bazelsteward.core

fun interface Environment {
fun get(name: String): String?
operator fun get(name: String): String?
fun getOrDefault(name: String, default: String): String = get(name) ?: default
fun getOrThrow(name: String): String = get(name) ?: throw RuntimeException("$name not found in environment")

Expand Down