Skip to content

Commit

Permalink
Add Shellcheck action and fix issues, also adds npm build script tests (
Browse files Browse the repository at this point in the history
  • Loading branch information
sverdlov93 authored Sep 26, 2023
1 parent a33abc9 commit b04accc
Show file tree
Hide file tree
Showing 24 changed files with 384 additions and 272 deletions.
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
41 changes: 38 additions & 3 deletions .github/workflows/scriptTests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,60 @@ concurrency:
cancel-in-progress: true
jobs:
Scripts-tests:
name: Script tests (${{ matrix.os }})
name: Script tests (${{ matrix.suite.os }})
defaults:
run:
shell: bash
strategy:
fail-fast: false
matrix:
os: [ ubuntu, windows, macos ]
runs-on: ${{ matrix.os }}-latest
suite:
- os: "ubuntu"

- os: "macos"

- os: "windows"
osSuffix: ".exe"
runs-on: ${{ matrix.suite.os }}-latest
steps:
- name: Checkout code
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${{ matrix.suite.osSuffix }} --version
if: ${{ matrix.suite.os != 'windows' }}

- name: Test Build CLI - bat
run: |
build/build.bat
./jf${{ matrix.suite.osSuffix }} --version
if: ${{ matrix.suite.os == 'windows' }}

- name: Test install npm - v2
working-directory: build/npm/v2
run: |
npm install
bin/jfrog${{ matrix.suite.osSuffix }} --version
- name: Test install npm - v2-jf
working-directory: build/npm/v2-jf
run: |
npm install
bin/jf${{ matrix.suite.osSuffix }} --version
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
78 changes: 41 additions & 37 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"
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
log "Docker is avaiable" "DEBUG"
}

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}"
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}" \
-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
13 changes: 7 additions & 6 deletions build/deb_rpm/v2-jf/build-scripts/rpm-install.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
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;
sudo mv jfrog-cli.repo /etc/yum.repos.d/;
#!/bin/bash

echo -e "[jfrog-cli]
name=jfrog-cli
baseurl=https://releases.jfrog.io/artifactory/jfrog-rpms
enabled=1
gpgcheck=0" | sudo tee /etc/yum.repos.d/jfrog-cli.repo >/dev/null
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

0 comments on commit b04accc

Please sign in to comment.