Skip to content

Commit

Permalink
Merge pull request #4 from miguelaferreira/add-github-command
Browse files Browse the repository at this point in the history
Add GitHub command
  • Loading branch information
miguelaferreira authored Jul 16, 2021
2 parents 50c882b + b072082 commit e33b98c
Show file tree
Hide file tree
Showing 30 changed files with 938 additions and 232 deletions.
119 changes: 77 additions & 42 deletions .github/scripts/create-native-image-build-config.sh
Original file line number Diff line number Diff line change
@@ -1,16 +1,29 @@
#!/bin/bash

set -euo pipefail
IFS=$'\n\t'

say() {
what="$@"
local what="$@"
echo "==> ${what}"
}

cmd() {
config_output_dir="${1}"
args="${*:2}"
java -agentlib:native-image-agent=config-output-dir="${config_output_dir}" -jar build/libs/devex-*-all.jar gitlab clone ${args}
local config_output_dir="${1}"
local args="${*:2}"
java -agentlib:native-image-agent=config-output-dir="${config_output_dir}" -jar build/libs/devex-*-all.jar ${args}
}

cmd_gitlab() {
local config_output_dir="${1}"
local args="${*:2}"
GITHUB_TOKEN="" cmd ${config_output_dir} gitlab clone ${args}
}

cmd_github() {
local config_output_dir="${1}"
local args="${*:2}"
GITLAB_TOKEN="" cmd ${config_output_dir} github clone ${args}
}

test_clones_dir="test-clones"
Expand All @@ -25,41 +38,63 @@ cmd "${native_image_config_dir}/no-clone/version" -V
say "Asking for tool help"
cmd "${native_image_config_dir}/no-clone/help" -h

local_path="${test_clones_dir}/public-without-token-ssh-no-submodules-trace"
say "Asking to clone a public group without using a token, via ssh, without submodules"
GITLAB_TOKEN="" cmd "${native_image_config_dir}/${local_path}-1" --trace gitlab-clone-example "${local_path}"

say "Asking to clone the same public group without using a token, via ssh, with submodules (effectively only initializing submodules)"
GITLAB_TOKEN="" cmd "${native_image_config_dir}/${local_path}-2" --trace gitlab-clone-example -r "${local_path}"

local_path="${test_clones_dir}/public-with-token-ssh-with-submodules-debug"
say "Asking to clone a public group using a token, via ssh, with submodules"
cmd "${native_image_config_dir}/${local_path}" --debug -r gitlab-clone-example "${local_path}"

local_path="${test_clones_dir}/public-with-token-https-with-submodules-verbose"
say "Asking to clone a public group using a token, via https, with submodules"
cmd "${native_image_config_dir}/${local_path}" -v -r -c HTTPS gitlab-clone-example "${local_path}"

local_path="${test_clones_dir}/private-without-token-ssh-with-submodules-verbose"
say "Asking to clone a private group without using a token, via ssh, with submodules"
GITLAB_TOKEN="" cmd "${native_image_config_dir}/${local_path}" -v -r gitlab-clone-example-private "${local_path}" || true

local_path="${test_clones_dir}/public-without-token-https-with-submodules-verbose"
say "Asking to clone a private group without using a token, via https, with submodules"
GITLAB_TOKEN="" cmd "${native_image_config_dir}/${local_path}" -v -r -c HTTPS gitlab-clone-example-private "${local_path}" || true

local_path="${test_clones_dir}/private-with-token-ssh-with-submodules-very-verbose"
say "Asking to clone a private group using a token, via ssh, with submodules"
cmd "${native_image_config_dir}/${local_path}" -x -r gitlab-clone-example-private "${local_path}"

local_path="${test_clones_dir}/public-with-token-https-with-submodules-very-verbose"
say "Asking to clone a private group using a token, via https, with submodules"
cmd "${native_image_config_dir}/${local_path}" -x -r -c HTTPS gitlab-clone-example-private "${local_path}"

local_path="${test_clones_dir}/public-by-id-with-token-very-verbose"
say "Asking to clone a public group by id using a token, via https, with submodules"
cmd "${native_image_config_dir}/${local_path}" -x -m id -r -c HTTPS 11961707 "${local_path}"

local_path="${test_clones_dir}/public-sub-group-by-full-path-with-token-very-verbose"
say "Asking to clone a public subgroup by full path using a token, via https, with submodules"
cmd "${native_image_config_dir}/${local_path}" -x -m full_path -r -c HTTPS gitlab-clone-example/sub-group-2/sub-group-3 "${local_path}"
################################################
# Gitlab
################################################
local_path="${test_clones_dir}/gitlab-public-without-token-ssh-no-submodules-trace"
say "[GITLAB] Asking to clone a public group without using a token, via ssh, without submodules"
GITLAB_TOKEN="" cmd_gitlab "${native_image_config_dir}/${local_path}-1" --trace gitlab-clone-example "${local_path}"

say "[GITLAB] Asking to clone the same public group without using a token, via ssh, with submodules (effectively only initializing submodules)"
GITLAB_TOKEN="" cmd_gitlab "${native_image_config_dir}/${local_path}-2" --trace gitlab-clone-example -r "${local_path}"

local_path="${test_clones_dir}/gitlab-public-with-token-ssh-with-submodules-debug"
say "[GITLAB] Asking to clone a public group using a token, via ssh, with submodules"
cmd_gitlab "${native_image_config_dir}/${local_path}" --debug -r gitlab-clone-example "${local_path}"

local_path="${test_clones_dir}/gitlab-public-with-token-https-with-submodules-verbose"
say "[GITLAB] Asking to clone a public group using a token, via https, with submodules"
cmd_gitlab "${native_image_config_dir}/${local_path}" -v -r -c HTTPS gitlab-clone-example "${local_path}"

local_path="${test_clones_dir}/gitlab-private-without-token-ssh-with-submodules-verbose"
say "[GITLAB] Asking to clone a private group without using a token, via ssh, with submodules"
GITLAB_TOKEN="" cmd_gitlab "${native_image_config_dir}/${local_path}" -v -r gitlab-clone-example-private "${local_path}" || true

local_path="${test_clones_dir}/gitlab-public-without-token-https-with-submodules-verbose"
say "[GITLAB] Asking to clone a private group without using a token, via https, with submodules"
GITLAB_TOKEN="" cmd_gitlab "${native_image_config_dir}/${local_path}" -v -r -c HTTPS gitlab-clone-example-private "${local_path}" || true

local_path="${test_clones_dir}/gitlab-private-with-token-ssh-with-submodules-very-verbose"
say "[GITLAB] Asking to clone a private group using a token, via ssh, with submodules"
cmd_gitlab "${native_image_config_dir}/${local_path}" -x -r gitlab-clone-example-private "${local_path}"

local_path="${test_clones_dir}/gitlab-public-with-token-https-with-submodules-very-verbose"
say "[GITLAB] Asking to clone a private group using a token, via https, with submodules"
cmd_gitlab "${native_image_config_dir}/${local_path}" -x -r -c HTTPS gitlab-clone-example-private "${local_path}"

local_path="${test_clones_dir}/gitlab-public-by-id-with-token-very-verbose"
say "[GITLAB] Asking to clone a public group by id using a token, via https, with submodules"
cmd_gitlab "${native_image_config_dir}/${local_path}" -x -m id -r -c HTTPS 11961707 "${local_path}"

local_path="${test_clones_dir}/gitlab-public-sub-group-by-full-path-with-token-very-verbose"
say "[GITLAB] Asking to clone a public subgroup by full path using a token, via https, with submodules"
cmd_gitlab "${native_image_config_dir}/${local_path}" -x -m full_path -r -c HTTPS gitlab-clone-example/sub-group-2/sub-group-3 "${local_path}"

################################################
# Github
################################################
local_path="${test_clones_dir}/github-org-without-token-ssh-no-submodules-trace"
say "[GITHUB] Asking to clone an organization without using a token, via ssh, without submodules"
GITHUB_TOKEN="" cmd_github "${native_image_config_dir}/${local_path}-1" --trace devex-cli-example "${local_path}"

local_path="${test_clones_dir}/github-org-with-token-ssh-with-submodules-trace"
say "[GITHUB] Asking to clone an organization using a token, via ssh, with submodules"
cmd_github "${native_image_config_dir}/${local_path}-1" --trace -r devex-cli-example "${local_path}"

local_path="${test_clones_dir}/github-org-without-token-https-without-submodules-debug"
say "[GITLAB] Asking to clone an organization using a token, via https, with submodules"
GITHUB_TOKEN="" cmd_github "${native_image_config_dir}/${local_path}" --debug -c HTTPS devex-cli-example "${local_path}"

local_path="${test_clones_dir}/github-org-with-token-https-with-submodules-debug"
say "[GITLAB] Asking to clone an organization using a token, via https, with submodules"
cmd_github "${native_image_config_dir}/${local_path}" --debug -c HTTPS -r devex-cli-example "${local_path}"
4 changes: 2 additions & 2 deletions .github/scripts/merge-native-image-build-config.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#!/bin/bash

set -euo pipefail
IFS=$'\n\t'

say() {
what="$@"
local what="$@"
echo "==> ${what}"
}

Expand All @@ -17,7 +18,6 @@ mkdir -p "${output_dir}"

[[ -d "${native_image_config_dir}" ]] || exit 1


say "Merging native-image build config"
input_dirs=""
for config_dir in "${native_image_config_dir}"/*/*; do
Expand Down
35 changes: 28 additions & 7 deletions .github/scripts/run-native-binary.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#!/bin/bash

set -euo pipefail
IFS=$'\n\t'

say() {
what="$@"
local what="$@"
echo "==> ${what}"
}

Expand All @@ -13,8 +14,11 @@ build/native-image/application -V
say "Asking for tool help"
build/native-image/application -h

local_path="ssh-no-submodules"
say "Asking to clone a group, via ssh, without submodules"
################################################
# Gitlab
################################################
local_path="gitlab-ssh-no-submodules"
say "Asking to clone group, via ssh, without submodules"
build/native-image/application gitlab clone -x gitlab-clone-example "${local_path}"
[[ ! -f "${local_path}/gitlab-clone-example/a-project/some-project-sub-module/README.md" ]]

Expand All @@ -25,32 +29,49 @@ cd "${local_path}/gitlab-clone-example/a-project"
[[ "$(git remote -v | head -n 1)" == *"git@"* ]]
cd -

local_path="ssh-with-submodules"
local_path="gitlab-ssh-with-submodules"
say "Asking to clone group, via ssh, with submodules"
build/native-image/application gitlab clone -x -r gitlab-clone-example "${local_path}"
[[ -f "${local_path}/gitlab-clone-example/a-project/some-project-sub-module/README.md" ]]
cd "${local_path}/gitlab-clone-example/a-project"
[[ "$(git remote -v | head -n 1)" == *"git@"* ]]
cd -

local_path="https-with-submodules"
local_path="gitlab-https-with-submodules"
say "Asking to clone group, via https, with submodules"
build/native-image/application gitlab clone -x -r -c HTTPS gitlab-clone-example "${local_path}"
[[ -f "${local_path}/gitlab-clone-example/a-project/some-project-sub-module/README.md" ]]
cd "${local_path}/gitlab-clone-example/a-project"
[[ "$(git remote -v | head -n 1)" == *"https://"* ]]
cd -

local_path="https-by-id"
local_path="gitlab-https-by-id"
say "Asking to clone group by id"
build/native-image/application gitlab clone -x -r -c HTTPS -m id 11961707 "${local_path}"
[[ -f "${local_path}/gitlab-clone-example/a-project/some-project-sub-module/README.md" ]]
cd "${local_path}/gitlab-clone-example/a-project"
[[ "$(git remote -v | head -n 1)" == *"https://"* ]]
cd -

local_path="ssh-by-full-path"
local_path="gitlab-ssh-by-full-path"
say "Asking to clone group by full path"
build/native-image/application gitlab clone -x -m full_path gitlab-clone-example/sub-group-2/sub-group-3 "${local_path}"
[[ -f "${local_path}/gitlab-clone-example/sub-group-2/sub-group-3/another-project/README.md" ]]

################################################
# Github
################################################
local_path="github-ssh-no-submodules"
say "Asking to clone organization, via ssh, without submodules"
build/native-image/application github clone -x devex-cli-example "${local_path}"
[[ -f "${local_path}/devex-cli-example/a-private-repository/README.md" ]]
[[ -f "${local_path}/devex-cli-example/a-public-repository/README.md" ]]

local_path="github-https-with-submodules"
say "Asking to clone organization, via https, with submodules"
build/native-image/application github clone -x -r -c HTTPS devex-cli-example "${local_path}"
[[ -f "${local_path}/devex-cli-example/a-private-repository/README.md" ]]
[[ -f "${local_path}/devex-cli-example/a-public-repository/README.md" ]]
cd "${local_path}/devex-cli-example/a-private-repository"
[[ "$(git remote -v | head -n 1)" == *"https://"* ]]
cd -
2 changes: 2 additions & 0 deletions .github/workflows/create-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,12 @@ jobs:
run: ./gradlew build nativeImage
env:
GITLAB_TOKEN: ${{ secrets.BOT_GITLAB_TOKEN_READ_API }}
GITHUB_TOKEN: ${{ secrets.BOT_GITHUB_TOKEN_READ_ORG_AND_REPO }}
- name: "[${{ runner.os }}] Run and test native image"
run: .github/scripts/run-native-binary.sh
env:
GITLAB_TOKEN: ${{ secrets.BOT_GITLAB_TOKEN_READ_API }}
GITHUB_TOKEN: ${{ secrets.BOT_GITHUB_TOKEN_READ_ORG_AND_REPO }}
- name: "[${{ runner.os }}] Clean up"
if: ${{ always() }}
run: sudo rm -rf ~/.ssh
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/development.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ jobs:
run: ./gradlew build
env:
GITLAB_TOKEN: ${{ secrets.BOT_GITLAB_TOKEN_READ_API }}
GITHUB_TOKEN: ${{ secrets.BOT_GITHUB_TOKEN_READ_ORG_AND_REPO }}
- name: "Publish Unit Test Results"
uses: EnricoMi/publish-unit-test-result-action/composite@v1
if: always()
Expand All @@ -55,14 +56,17 @@ jobs:
.github/scripts/merge-native-image-build-config.sh linux
env:
GITLAB_TOKEN: ${{ secrets.BOT_GITLAB_TOKEN_READ_API }}
GITHUB_TOKEN: ${{ secrets.BOT_GITHUB_TOKEN_READ_ORG_AND_REPO }}
- name: "Gradle nativeImage"
run: ./gradlew nativeImage
env:
GITLAB_TOKEN: ${{ secrets.BOT_GITLAB_TOKEN_READ_API }}
GITHUB_TOKEN: ${{ secrets.BOT_GITHUB_TOKEN_READ_ORG_AND_REPO }}
- name: "Run and test native binary"
run: .github/scripts/run-native-binary.sh
env:
GITLAB_TOKEN: ${{ secrets.BOT_GITLAB_TOKEN_READ_API }}
GITHUB_TOKEN: ${{ secrets.BOT_GITHUB_TOKEN_READ_ORG_AND_REPO }}
- uses: EndBug/add-and-commit@v7 # You can change this to use a specific version
with:
add: "src/main/resources/META-INF/native-image"
Expand Down
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ java {

test {
environment "GITLAB_TOKEN", System.getenv('GITLAB_TOKEN')
environment "GITHUB_TOKEN", System.getenv('GITHUB_TOKEN')
moduleOptions {
runOnClasspath = true
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/devex/DevexCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
versionProvider = DevexCommand.AppVersionProvider.class,
sortOptions = false,
usageHelpAutoWidth = true,
subcommands = {GitlabCommand.class},
subcommands = {GitlabCommand.class, GithubCommand.class},
scope = CommandLine.ScopeType.INHERIT
)
public class DevexCommand {
Expand Down
Loading

0 comments on commit e33b98c

Please sign in to comment.