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

Add Shellcheck action and fix issues, also adds npm build script tests #2208

Merged
merged 40 commits into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
86700bc
copy dir
sverdlov93 Sep 5, 2023
6bb231f
copy dir
sverdlov93 Sep 7, 2023
f4a6e78
Merge branch 'dev' of https://github.com/jfrog/jfrog-cli into anlyzer…
sverdlov93 Sep 10, 2023
18097da
Merge branch 'dev' of https://github.com/jfrog/jfrog-cli into anlyzer…
sverdlov93 Sep 11, 2023
c06f602
Merge branch 'dev' of https://github.com/jfrog/jfrog-cli into anlyzer…
sverdlov93 Sep 12, 2023
ac0598e
fix build script
sverdlov93 Sep 12, 2023
9d8d6b0
fix build script
sverdlov93 Sep 14, 2023
aab974a
Merge branch 'dev' of https://github.com/jfrog/jfrog-cli into anlyzer…
sverdlov93 Sep 14, 2023
db0937e
fix build script
sverdlov93 Sep 14, 2023
9a5ea33
fix build script
sverdlov93 Sep 14, 2023
17881f9
fix build script
sverdlov93 Sep 14, 2023
2f16607
fix build script
sverdlov93 Sep 14, 2023
76aaf7a
Merge branch 'dev' of https://github.com/jfrog/jfrog-cli into anlyzer…
sverdlov93 Sep 14, 2023
b7d3887
fix build script
sverdlov93 Sep 14, 2023
beac533
fix build script
sverdlov93 Sep 14, 2023
088cd21
fix build script
sverdlov93 Sep 14, 2023
bc05a54
Merge branch 'dev' into anlyzer-version
sverdlov93 Sep 21, 2023
d67d3cc
fix build script
sverdlov93 Sep 21, 2023
e0f725a
fix build script
sverdlov93 Sep 21, 2023
58dbe50
fix build script
sverdlov93 Sep 21, 2023
4774f3f
fix build script
sverdlov93 Sep 21, 2023
ff45c44
fix build script
sverdlov93 Sep 21, 2023
bcdb69d
fix build script
sverdlov93 Sep 21, 2023
039f25e
fix build script
sverdlov93 Sep 21, 2023
4000316
fix build script
sverdlov93 Sep 21, 2023
f1690d7
fix build script
sverdlov93 Sep 21, 2023
e39e3f4
fix build script
sverdlov93 Sep 21, 2023
63090a6
fix build script
sverdlov93 Sep 21, 2023
f5f947f
fix build script
sverdlov93 Sep 21, 2023
2c835f5
fix build script
sverdlov93 Sep 21, 2023
e1c223c
fix build script
sverdlov93 Sep 21, 2023
97bd4d2
fix build script
sverdlov93 Sep 21, 2023
a2acfd8
Update .github/workflows/scriptTests.yml
sverdlov93 Sep 26, 2023
645cc8f
Update .github/workflows/scriptTests.yml
sverdlov93 Sep 26, 2023
0329d80
Update .github/workflows/scriptTests.yml
sverdlov93 Sep 26, 2023
29ca950
Update build/deb_rpm/v2-jf/build-scripts/pack.sh
sverdlov93 Sep 26, 2023
8777656
fix build script
sverdlov93 Sep 26, 2023
099c3b2
fix build script
sverdlov93 Sep 26, 2023
eacbd5f
fix build script
sverdlov93 Sep 26, 2023
9d2f938
Merge branch 'dev' into anlyzer-version
sverdlov93 Sep 26, 2023
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
12 changes: 12 additions & 0 deletions .github/workflows/analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,15 @@ jobs:
uses: securego/gosec@master
with:
args: -exclude G204,G301,G302,G304,G306 -tests -exclude-dir \.*test\.* ./...

ShellCheck:
name: Shellcheck
runs-on: ubuntu-latest
steps:
- name: Checkout Source
uses: actions/checkout@v3

- name: Run ShellCheck
uses: ludeeus/action-shellcheck@master
with:
ignore_paths: '*test*'
3 changes: 1 addition & 2 deletions .github/workflows/dockerTests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v3
with:
# We are temporarily downgrading to Go 1.20.5 due to a bug in version 1.20.6 that causes Docker tests to fail.
go-version: 1.20.5
go-version: 1.20.x
- name: Checkout code
uses: actions/checkout@v3
with:
Expand Down
18 changes: 18 additions & 0 deletions .github/workflows/scriptTests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,29 @@ jobs:
uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.sha }}

- name: Test install CLI - jf
run: sh build/installcli/jf.sh && jf --version

- name: Test install CLI - jfrog
run: sh build/installcli/jfrog.sh && jfrog --version

- name: Test get CLI - jf
run: sh build/getcli/jf.sh && ./jf --version

- name: Test get CLI - jfrog
run: sh build/getcli/jfrog.sh && ./jfrog --version

- name: Test Build CLI (sh)
run: sh build/build.sh && ./jf --version
if: ${{ matrix.os != 'windows' }}

- name: Test Build CLI (bat)
run: build/build.bat && ./jf.exe --version
if: ${{ matrix.os == 'windows' }}

sverdlov93 marked this conversation as resolved.
Show resolved Hide resolved
- name: Test Build npm v2
run: cd build/npm/v2 && npm install
sverdlov93 marked this conversation as resolved.
Show resolved Hide resolved

- name: Test Build npm v2-jf
run: cd build/npm/v2-jf && npm install
sverdlov93 marked this conversation as resolved.
Show resolved Hide resolved
sverdlov93 marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 1 addition & 1 deletion build/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ if [ $# -eq 0 ]
exe_name="$1"
fi

CGO_ENABLED=0 go build -o $exe_name -ldflags '-w -extldflags "-static"' main.go
CGO_ENABLED=0 go build -o "$exe_name" -ldflags '-w -extldflags "-static"' main.go
echo "The $exe_name executable was successfully created."
4 changes: 2 additions & 2 deletions build/chocolatey/v2-jf/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ choco pack version=<version>
```

This will create the file _build/chocolatey/jfrog-cli.\<version\>.nupkg which can be
installed with Chcolatey
installed with Chocolatey

```powershell
choco install jfrog-cli.<version>.nupkg
```

See Chocolatey's official documenattion [here](https://chocolatey.org/docs/create-packages)
See Chocolatey's official documentation [here](https://chocolatey.org/docs/create-packages)

[choco-dockerfile-pr]: https://github.com/chocolatey/choco/pull/1153
[choco-dockerfile]: https://github.com/chocolatey/choco/tree/master/docker
Expand Down
4 changes: 2 additions & 2 deletions build/chocolatey/v2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ choco pack version=<version>
```

This will create the file _build/chocolatey/jfrog-cli.\<version\>.nupkg which can be
installed with Chcolatey
installed with Chocolatey

```powershell
choco install jfrog-cli.<version>.nupkg
```

See Chocolatey's official documenattion [here](https://chocolatey.org/docs/create-packages)
See Chocolatey's official documentation [here](https://chocolatey.org/docs/create-packages)

[choco-dockerfile-pr]: https://github.com/chocolatey/choco/pull/1153
[choco-dockerfile]: https://github.com/chocolatey/choco/tree/master/docker
Expand Down
2 changes: 2 additions & 0 deletions build/deb_rpm/v2-jf/build-scripts/deb-install.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/bin/bash

wget -qO - https://releases.jfrog.io/artifactory/api/gpg/key/public | apt-key add -;
echo "deb https://releases.jfrog.io/artifactory/jfrog-debs xenial contrib" | sudo tee -a /etc/apt/sources.list;
apt update;
Expand Down
80 changes: 42 additions & 38 deletions build/deb_rpm/v2-jf/build-scripts/pack.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,11 @@ errorExit() {
}

checkDockerAccess() {
log "Checking docker" "DEBUG"
docker -v > /dev/null 2>&1 && docker ps > /dev/null 2>&1
if [ $? -ne 0 ]; then
errorExit "Must run as user that can execute docker commands"
fi
log "Docker is avaiable" "DEBUG"
if docker -v > /dev/null 2>&1 && docker ps > /dev/null 2>&1; then
log "Docker is available" "DEBUG"
else
errorExit "Must run as a user that can execute docker commands"
fi
sverdlov93 marked this conversation as resolved.
Show resolved Hide resolved
}

exitWithUsage(){
Expand All @@ -64,15 +63,15 @@ createDEBPackage(){
local flavour="deb"

# cleanup old files and containers
rm -f ${JFROG_CLI_PKG}/${JFROG_CLI_PREFIX}*${VERSION_FORMATTED}*.${flavour}
rm -f "${JFROG_CLI_PKG}"/${JFROG_CLI_PREFIX}*"${VERSION_FORMATTED}"*.${flavour}
sverdlov93 marked this conversation as resolved.
Show resolved Hide resolved
docker rm -f "${RPM_BUILDER_NAME}" 2>/dev/null

log "Building ${JFROG_CLI_PREFIX} ${flavour} ${JFROG_CLI_VERSION} on ${DEB_BUILD_IMAGE} image"

docker run -t --rm -v "${JFROG_CLI_HOME}/${flavour}":${DEB_IMAGE_ROOT_DIR}/src \
-v "${JFROG_CLI_PKG}":${DEB_IMAGE_ROOT_DIR}/pkg \
--name ${DEB_BUILDER_NAME} \
${DEB_BUILD_IMAGE} bash -c "\
"${DEB_BUILD_IMAGE}" bash -c "\
\
echo '' && echo '' && \
apt-get update && \
Expand Down Expand Up @@ -107,15 +106,15 @@ createRPMPackage(){
local flavour="rpm"

# cleanup old files and containers
rm -f ${JFROG_CLI_PKG}/${JFROG_CLI_PREFIX}*${VERSION_FORMATTED}*.${flavour}
rm -f "${JFROG_CLI_PKG}"/${JFROG_CLI_PREFIX}*"${VERSION_FORMATTED}"*.${flavour}
docker rm -f "${RPM_BUILDER_NAME}" 2>/dev/null

log "Building ${JFROG_CLI_PREFIX} ${flavour} ${JFROG_CLI_VERSION} on ${RPM_BUILD_IMAGE} image"

docker run -t --rm -v "${JFROG_CLI_HOME}/${flavour}":${RPM_IMAGE_ROOT_DIR}/src \
-v "${JFROG_CLI_PKG}":${RPM_IMAGE_ROOT_DIR}/pkg \
--name ${RPM_BUILDER_NAME} \
${RPM_BUILD_IMAGE} bash -c "\
"${RPM_BUILD_IMAGE}" bash -c "\
echo '' && echo '' && \
yum install -y ${RPM_DEPS} && \
echo '' && echo '' && \
Expand Down Expand Up @@ -159,10 +158,10 @@ rpmSign()(
if [[ -f "${filePath}" && -f "${gpgFileInHost}" ]]; then
log ""; log "";
log "Initiating rpm sign on ${filePath}..."
docker run --rm --name cli-rpm-sign -v "${filePath}":${filePathInImage} \
docker run --rm --name cli-rpm-sign -v "${filePath}"":${filePathInImage}" \
sverdlov93 marked this conversation as resolved.
Show resolved Hide resolved
-v "${gpgFileInHost}":"${gpgFileInImage}" \
-v "${JFROG_CLI_HOME}/build-scripts":${RPM_IMAGE_ROOT_DIR}/src \
${RPM_SIGN_IMAGE} \
"${RPM_SIGN_IMAGE}" \
bash -c "yum install -y expect rpm-sign pinentry && \
${RPM_IMAGE_ROOT_DIR}/src/${rpmSignScript} \"${gpgFileInImage}\" \"${keYID}\" \"${passphrase}\" \"${filePathInImage}\" \
&& exit 0 || exit 1" \
Expand All @@ -178,7 +177,7 @@ rpmSign()(
runTests()(
local flavour=$1

[ ! -z "${flavour}" ] || { echo "Flavour is mandatory to run tests"; exit 1; }
[ -n "${flavour}" ] || { echo "Flavour is mandatory to run tests"; exit 1; }

local fileName="${JFROG_CLI_PREFIX}-${VERSION_FORMATTED}.${flavour}"
local filePath="${JFROG_CLI_PKG}"/${fileName}
Expand All @@ -199,7 +198,7 @@ runTests()(
if [ -f "${filePath}" ]; then
log ""; log "";
log "Testing ${filePath} on ${testImage}..."
docker run --rm --name cli-test -v "${filePath}":${filePathInImage} ${testImage} \
docker run --rm --name cli-test -v "${filePath}:${filePathInImage}" "${testImage}" \
bash -c "${installCommand} && jf -version | grep ${JFROG_CLI_VERSION} && \
${signatureTestCommand} && exit 0 || exit 1" \
|| { echo "ERROR: ############### Test failed! ###################"; exit 1; }
Expand All @@ -214,28 +213,28 @@ runTests()(
getArch(){
local image=$1

[ ! -z "$image" ] || return 0;
[ -n "$image" ] || return 0;

docker run --rm ${image} bash -c "uname -m 2>/dev/null" 2>/dev/null
docker run --rm "${image}" bash -c "uname -m 2>/dev/null" 2>/dev/null
}

createPackage(){
local flavour=$1

[ ! -z "${flavour}" ] || errorExit "Flavour is not passed to createPackage method"
[ -n "${flavour}" ] || errorExit "Flavour is not passed to createPackage method"

cp -f "${JFROG_CLI_BINARY}" "${JFROG_CLI_HOME}"/${flavour}/jf \
cp -f "${JFROG_CLI_BINARY}" "${JFROG_CLI_HOME}"/"${flavour}"/jf \
|| errorExit "Failed to copy ${JFROG_CLI_BINARY} to ${JFROG_CLI_HOME}/${flavour}/jf"


case "$flavour" in
rpm)
[ ! -z "${JFROG_CLI_RPM_ARCH}" ] || JFROG_CLI_RPM_ARCH=$(getArch "${RPM_BUILD_IMAGE}")
[ -n "${JFROG_CLI_RPM_ARCH}" ] || JFROG_CLI_RPM_ARCH=$(getArch "${RPM_BUILD_IMAGE}")
VERSION_FORMATTED="${JFROG_CLI_VERSION}.${JFROG_CLI_RPM_ARCH}"
createRPMPackage
;;
deb)
[ ! -z "${JFROG_CLI_DEB_ARCH}" ] || JFROG_CLI_DEB_ARCH=$(getArch "${DEB_BUILD_IMAGE}")
[ -n "${JFROG_CLI_DEB_ARCH}" ] || JFROG_CLI_DEB_ARCH=$(getArch "${DEB_BUILD_IMAGE}")
VERSION_FORMATTED="${JFROG_CLI_VERSION}.${JFROG_CLI_DEB_ARCH}"
createDEBPackage
;;
Expand All @@ -248,7 +247,7 @@ createPackage(){
setBuildImage(){
local arch="$1"

[ ! -z "${arch}" ] || errorExit "Architecture is not passed to setBuildImage method"
[ -n "${arch}" ] || errorExit "Architecture is not passed to setBuildImage method"

case "$1" in
x86_64)
Expand All @@ -262,7 +261,7 @@ setBuildImage(){
}

main(){
while [[ $# > 0 ]]; do
while [[ $# -gt 0 ]]; do
case "$1" in
-f | --flavour)
flavours="$2"
Expand Down Expand Up @@ -323,21 +322,21 @@ main(){
esac
done

: ${flavours:="rpm deb"}
: ${JFROG_CLI_RUN_TEST:="false"}
: ${RPM_BUILD_IMAGE:="centos:8"}
: ${RPM_SIGN_IMAGE:="centos:7"}
: ${DEB_BUILD_IMAGE:="ubuntu:16.04"}
: ${DEB_TEST_IMAGE:="${DEB_BUILD_IMAGE}"}
: ${RPM_TEST_IMAGE:="${RPM_BUILD_IMAGE}"}
: ${JFROG_CLI_RELEASE_VERSION:="1"}
: ${RPM_SIGN_PASSPHRASE:="$(cat $RPM_SIGN_PASSPHRASE_FILE)"}
: ${RPM_SIGN_KEY_ID:="JFrog Inc."}
: ${RPM_SIGN_KEY_NAME:="RPM-GPG-KEY-jfrog-cli"}

[ ! -z "${JFROG_CLI_BINARY}" ] || exitWithUsage "jfrog cli binary is not passed"
: "${flavours:="rpm deb"}"
: "${JFROG_CLI_RUN_TEST:="false"}"
: "${RPM_BUILD_IMAGE:="centos:8"}"
: "${RPM_SIGN_IMAGE:="centos:7"}"
: "${DEB_BUILD_IMAGE:="ubuntu:16.04"}"
: "${DEB_TEST_IMAGE:="${DEB_BUILD_IMAGE}"}"
: "${RPM_TEST_IMAGE:="${RPM_BUILD_IMAGE}"}"
: "${JFROG_CLI_RELEASE_VERSION:="1"}"
: "${RPM_SIGN_PASSPHRASE:=$(cat "$RPM_SIGN_PASSPHRASE_FILE")}"
: "${RPM_SIGN_KEY_ID:="JFrog Inc."}"
: "${RPM_SIGN_KEY_NAME:="RPM-GPG-KEY-jfrog-cli"}"

[ -n "${JFROG_CLI_BINARY}" ] || exitWithUsage "jfrog cli binary is not passed"
[ -f "$JFROG_CLI_BINARY" ] || exitWithUsage "jfrog cli binary is not available at $JFROG_CLI_BINARY"
[ ! -z "${JFROG_CLI_VERSION}" ] || exitWithUsage "version is not passed, pass the version to be built"
[ -n "${JFROG_CLI_VERSION}" ] || exitWithUsage "version is not passed, pass the version to be built"

if [[ "$flavours" == *"rpm"* ]] && [[ -z "${RPM_SIGN_PASSPHRASE}" || "${RPM_SIGN_PASSPHRASE}" == "" ]]; then
echo "ERROR: RPM_SIGN_PASSPHRASE environment variable is not set"
Expand All @@ -351,8 +350,13 @@ main(){

for flavour in $flavours; do
createPackage "$flavour"
[[ "${flavour}" == "rpm" ]] && rpmSign || true
[[ "${JFROG_CLI_RUN_TEST}" == "true" ]] && runTests "${flavour}" || true
if [[ "${flavour}" == "rpm" ]]; then
rpmSign
fi

if [[ "${JFROG_CLI_RUN_TEST}" == "true" ]]; then
runTests "${flavour}"
fi
done

log "...and Done!"
Expand Down
14 changes: 9 additions & 5 deletions build/deb_rpm/v2-jf/build-scripts/rpm-install.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
echo "[jfrog-cli]" > jfrog-cli.repo;
echo "name=jfrog-cli" >> jfrog-cli.repo;
echo "baseurl=https://releases.jfrog.io/artifactory/jfrog-rpms" >> jfrog-cli.repo;
echo "enabled=1" >> jfrog-cli.repo;
echo "gpgcheck=0" >> jfrog-cli.repo;
#!/bin/bash

{
echo "[jfrog-cli]"
echo "name=jfrog-cli"
echo "baseurl=https://releases.jfrog.io/artifactory/jfrog-rpms"
echo "enabled=1"
echo "gpgcheck=0"
} >> jfrog-cli.repo
sudo mv jfrog-cli.repo /etc/yum.repos.d/;
sverdlov93 marked this conversation as resolved.
Show resolved Hide resolved
yum install -y jfrog-cli-v2-jf;
11 changes: 7 additions & 4 deletions build/deb_rpm/v2-jf/build-scripts/rpm-sign.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,14 @@ rpmInitSigning(){

log "Initializing rpm sign..."

gpg --allow-secret-key-import --import ${gpgKeyFile} && \
gpg --allow-secret-key-import --import "${gpgKeyFile}" && \
gpg --export -a "${keyID}" > /tmp/tmpFile && \
rpm --import /tmp/tmpFile && \
rpm -q gpg-pubkey --qf '%{name}-%{version}-%{release} --> %{summary}\n' | grep "${keyID}" || \
{ echo "ERROR: RPM signature initialization failed!" >&2; exit 1; }
if rpm --import /tmp/tmpFile && rpm -q gpg-pubkey --qf '%{name}-%{version}-%{release} --> %{summary}\n' | grep "${keyID}"; then
echo "RPM signature initialization succeeded."
else
echo "ERROR: RPM signature initialization failed!" >&2
exit 1
fi

rpmEditRpmMacro "${keyID}" || \
{ echo "ERROR: Configuring rpm macro failed!" >&2; exit 1; }
Expand Down
2 changes: 2 additions & 0 deletions build/deb_rpm/v2/build-scripts/deb-install.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/bin/bash

wget -qO - https://releases.jfrog.io/artifactory/api/gpg/key/public | apt-key add -;
echo "deb https://releases.jfrog.io/artifactory/jfrog-debs xenial contrib" | sudo tee -a /etc/apt/sources.list;
apt update;
Expand Down
Loading
Loading