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

fix(RELEASE-1078): linting issues in publish-pyxis-repository #742

Open
wants to merge 1 commit into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions tasks/publish-pyxis-repository/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ shouldn't cause any problems, because RHEC will ignore repos with no published i
| dataPath | Path to the JSON string of the merged data to use in the data workspace | No | |
| resultsDirPath | Path to the results directory in the data workspace | No | |

## Changes in 3.0.1
* Fix shellcheck/checkton linting issues in the task and tests

## Changes in 3.0.0
* data json is now mandatory - technically, for some use cases the file is not needed, but requiring it always
makes it consistent with other tasks and it also makes the task script more readable
Expand Down
23 changes: 13 additions & 10 deletions tasks/publish-pyxis-repository/publish-pyxis-repository.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ kind: Task
metadata:
name: publish-pyxis-repository
labels:
app.kubernetes.io/version: "3.0.0"
app.kubernetes.io/version: "3.0.1"
annotations:
tekton.dev/pipelines.minVersion: "0.12.1"
tekton.dev/tags: release
Expand Down Expand Up @@ -87,7 +87,10 @@ spec:

# Disable trace logging to avoid leaking of cert+key
set +x
# These variables come from the tekton env so disable shellcheck on them
# shellcheck disable=SC2154
echo "${pyxisCert}" > /tmp/crt
# shellcheck disable=SC2154
echo "${pyxisKey}" > /tmp/key
set -x

Expand Down Expand Up @@ -115,29 +118,29 @@ spec:
# Default to false
skipRepoPublishing="$(jq -r ".pyxis.skipRepoPublishing // false" "${DATA_FILE}")"

defaultPushSourceContainer=$(jq -r '.mapping.defaults.pushSourceContainer' ${DATA_FILE} || echo false)
defaultPushSourceContainer=$(jq -r '.mapping.defaults.pushSourceContainer' "${DATA_FILE}" || echo false)

application=$(jq -r '.application' "${SNAPSHOT_SPEC_FILE}")
printf 'Beginning "%s" for "%s"\n\n' "$(context.task.name)" "$application"

NUM_COMPONENTS=$(jq '.components | length' "${SNAPSHOT_SPEC_FILE}")
for ((i = 0; i < $NUM_COMPONENTS; i++))
for ((i = 0; i < NUM_COMPONENTS; i++))
do
COMPONENT=$(jq -c --argjson i "$i" '.components[$i]' "${SNAPSHOT_SPEC_FILE}")
PAYLOAD='{"published":true}'
COMPONENT_NAME=$(jq -r '.name' <<< "$COMPONENT")
REPOSITORY=$(jq -r '.repository' <<< $COMPONENT)
REPOSITORY=$(jq -r '.repository' <<< "$COMPONENT")
PYXIS_REPOSITORY=${REPOSITORY##*/}
# Replace "----" with "/"
PYXIS_REPOSITORY=${PYXIS_REPOSITORY//----//}
PYXIS_REPOSITORY_JSON=$(curl --retry 5 --key /tmp/key --cert /tmp/crt \
"${PYXIS_URL}/v1/repositories/registry/${PYXIS_REGISTRY}/repository/${PYXIS_REPOSITORY}" -X GET)

PYXIS_REPOSITORY_ID=$(jq -r '._id // ""' <<< $PYXIS_REPOSITORY_JSON)
PYXIS_REPOSITORY_ID=$(jq -r '._id // ""' <<< "$PYXIS_REPOSITORY_JSON")
if [ -z "$PYXIS_REPOSITORY_ID" ]; then
echo Error: Unable to get Container Repository object id from Pyxis
echo "Pyxis response for ${PYXIS_REGISTRY}/${PYXIS_REPOSITORY}:"
echo $PYXIS_REPOSITORY_JSON
echo "$PYXIS_REPOSITORY_JSON"
exit 1
fi

Expand All @@ -154,15 +157,15 @@ spec:

# Set source_container_image_enabled based on pushSourceContainer value in components or use default if
# it is not set in the component
if [[ $(jq -r '.pushSourceContainer' <<< $COMPONENT) == "true" ]] ||
[[ $(jq 'has("pushSourceContainer")' <<< $COMPONENT) == "false" && \
if [[ $(jq -r '.pushSourceContainer' <<< "$COMPONENT") == "true" ]] ||
[[ $(jq 'has("pushSourceContainer")' <<< "$COMPONENT") == "false" && \
${defaultPushSourceContainer} == "true" ]] ; then
PAYLOAD=$(jq -c '. += {"source_container_image_enabled":true}' <<< $PAYLOAD)
PAYLOAD=$(jq -c '. += {"source_container_image_enabled":true}' <<< "$PAYLOAD")
fi

# verify that publish_on_push is set to true.
# otherwise, do not publish the image.
PYXIS_REPOSITORY_PUBLISH_ON_PUSH=$(jq -r '.publish_on_push // "false"' <<< $PYXIS_REPOSITORY_JSON)
PYXIS_REPOSITORY_PUBLISH_ON_PUSH=$(jq -r '.publish_on_push // "false"' <<< "$PYXIS_REPOSITORY_JSON")
if [ "${PYXIS_REPOSITORY_PUBLISH_ON_PUSH}" != "true" ] ; then
echo "WARNING: repository ${PYXIS_REGISTRY}/${PYXIS_REPOSITORY} is marked as publish_on_push = false"
echo "Skipping the setting of the published flag."
Expand Down
2 changes: 1 addition & 1 deletion tasks/publish-pyxis-repository/tests/mocks.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env sh
#!/usr/bin/env bash
set -eux

# mocks to be injected into task step scripts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ spec:
- name: setup-values
image: quay.io/konflux-ci/release-service-utils:e633d51cd41d73e4b3310face21bb980af7a662f
script: |
#!/usr/bin/env sh
#!/usr/bin/env bash
set -eux

mkdir "$(workspaces.data.path)"/results

cat > $(workspaces.data.path)/snapshot_spec.json << EOF
cat > "$(workspaces.data.path)/snapshot_spec.json" << EOF
{
"application": "my-app",
"components": [
Expand All @@ -46,7 +46,7 @@ spec:
}
EOF

cat > $(workspaces.data.path)/mydata.json << EOF
cat > "$(workspaces.data.path)/mydata.json" << EOF
{
"mapping": {
"defaults": {
Expand Down Expand Up @@ -83,28 +83,28 @@ spec:
- name: check-result
image: quay.io/konflux-ci/release-service-utils:e633d51cd41d73e4b3310face21bb980af7a662f
script: |
#!/usr/bin/env sh
#!/usr/bin/env bash
set -eux

if [ $(cat $(workspaces.data.path)/mock_curl.txt | wc -l) != 6 ]; then
if [ "$(wc -l < "$(workspaces.data.path)/mock_curl.txt")" != 6 ]; then
echo Error: curl was expected to be called 6 times. Actual calls:
cat $(workspaces.data.path)/mock_curl.txt
cat "$(workspaces.data.path)/mock_curl.txt"
exit 1
fi

[[ $(cat $(workspaces.data.path)/mock_curl.txt | head -n 1) \
[[ "$(head -n 1 "$(workspaces.data.path)/mock_curl.txt")" \
== *"/my-product/my-image1 "* ]]
[[ $(cat $(workspaces.data.path)/mock_curl.txt | head -n 2 | tail -n 1) \
[[ "$(head -n 2 "$(workspaces.data.path)/mock_curl.txt" | tail -n 1)" \
== *'"source_container_image_enabled":true}' ]]

[[ $(cat $(workspaces.data.path)/mock_curl.txt | head -n 3 | tail -n 1) \
[[ "$(head -n 3 "$(workspaces.data.path)/mock_curl.txt" | tail -n 1)" \
== *"/my-product/my-image2 "* ]]
[[ $(cat $(workspaces.data.path)/mock_curl.txt | head -n 4 | tail -n 1) \
[[ "$(head -n 4 "$(workspaces.data.path)/mock_curl.txt" | tail -n 1)" \
!= *'"source_container_image_enabled":true}' ]]

[[ $(cat $(workspaces.data.path)/mock_curl.txt | head -n 5 | tail -n 1) \
[[ "$(head -n 5 "$(workspaces.data.path)/mock_curl.txt" | tail -n 1)" \
== *"/my-product/my-image3 "* ]]
[[ $(cat $(workspaces.data.path)/mock_curl.txt | tail -n 1) \
[[ "$(tail -n 1 "$(workspaces.data.path)/mock_curl.txt")" \
== *'"source_container_image_enabled":true}' ]]
runAfter:
- run-task
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ spec:
- name: setup-values
image: quay.io/konflux-ci/release-service-utils:e633d51cd41d73e4b3310face21bb980af7a662f
script: |
#!/usr/bin/env sh
#!/usr/bin/env bash
set -eux

mkdir "$(workspaces.data.path)"/results

cat > $(workspaces.data.path)/snapshot_spec.json << EOF
cat > "$(workspaces.data.path)/snapshot_spec.json" << EOF
{
"application": "my-app",
"components": [
Expand Down Expand Up @@ -71,16 +71,16 @@ spec:
- name: check-result
image: quay.io/konflux-ci/release-service-utils:e633d51cd41d73e4b3310face21bb980af7a662f
script: |
#!/usr/bin/env sh
#!/usr/bin/env bash
set -eux

if [ $(cat $(workspaces.data.path)/mock_curl.txt | wc -l) != 1 ]; then
if [ "$(wc -l < "$(workspaces.data.path)/mock_curl.txt")" != 1 ]; then
echo Error: curl was expected to be called 1 time. Actual calls:
cat $(workspaces.data.path)/mock_curl.txt
cat "$(workspaces.data.path)/mock_curl.txt"
exit 1
fi

[[ $(cat $(workspaces.data.path)/mock_curl.txt | head -n 1) \
[[ "$(head -n 1 "$(workspaces.data.path)/mock_curl.txt")" \
== *"/my-product/my-image0 "* ]]
runAfter:
- run-task
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ spec:
- name: setup-values
image: quay.io/konflux-ci/release-service-utils:e633d51cd41d73e4b3310face21bb980af7a662f
script: |
#!/usr/bin/env sh
#!/usr/bin/env bash
set -eux

mkdir "$(workspaces.data.path)"/results

cat > $(workspaces.data.path)/snapshot_spec.json << EOF
cat > "$(workspaces.data.path)/snapshot_spec.json" << EOF
{
"application": "my-app",
"components": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ spec:
- name: setup-values
image: quay.io/konflux-ci/release-service-utils:e633d51cd41d73e4b3310face21bb980af7a662f
script: |
#!/usr/bin/env sh
#!/usr/bin/env bash
set -eux

mkdir "$(workspaces.data.path)"/results

cat > $(workspaces.data.path)/snapshot_spec.json << EOF
cat > "$(workspaces.data.path)/snapshot_spec.json" << EOF
{
"application": "my-app",
"components": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ spec:
- name: setup-values
image: quay.io/konflux-ci/release-service-utils:e633d51cd41d73e4b3310face21bb980af7a662f
script: |
#!/usr/bin/env sh
#!/usr/bin/env bash
set -eux

mkdir -p "$(workspaces.data.path)/results"

cat > $(workspaces.data.path)/snapshot_spec.json << EOF
cat > "$(workspaces.data.path)/snapshot_spec.json" << EOF
{
"application": "my-app",
"components": [
Expand Down Expand Up @@ -85,7 +85,7 @@ spec:
- name: check-result
image: quay.io/konflux-ci/release-service-utils:e633d51cd41d73e4b3310face21bb980af7a662f
script: |
#!/usr/bin/env sh
#!/usr/bin/env bash
set -eux

RESULTS_FILE="$(workspaces.data.path)/results/publish-pyxis-repository-results.json"
Expand Down Expand Up @@ -120,23 +120,23 @@ spec:
exit 1
fi

if [ $(cat $(workspaces.data.path)/mock_curl.txt | wc -l) != 6 ]; then
if [ "$(wc -l < "$(workspaces.data.path)/mock_curl.txt")" != 6 ]; then
echo Error: curl was expected to be called 6 times. Actual calls:
cat $(workspaces.data.path)/mock_curl.txt
cat "$(workspaces.data.path)/mock_curl.txt"
exit 1
fi

[[ $(cat $(workspaces.data.path)/mock_curl.txt | head -n 1) \
[[ "$(head -n 1 "$(workspaces.data.path)/mock_curl.txt")" \
== *"/my-product/my-image1 "* ]]
[[ $(cat $(workspaces.data.path)/mock_curl.txt | head -n 2 | tail -n 1) \
[[ "$(head -n 2 "$(workspaces.data.path)/mock_curl.txt" | tail -n 1)" \
== *"/id/1 "* ]]
[[ $(cat $(workspaces.data.path)/mock_curl.txt | head -n 3 | tail -n 1) \
[[ "$(head -n 3 "$(workspaces.data.path)/mock_curl.txt" | tail -n 1)" \
== *"/my-product/my-image5 "* ]]
[[ $(cat $(workspaces.data.path)/mock_curl.txt | head -n 4 | tail -n 1) \
[[ "$(head -n 4 "$(workspaces.data.path)/mock_curl.txt" | tail -n 1)" \
== *"/id/3 "* ]]
[[ $(cat $(workspaces.data.path)/mock_curl.txt | head -n 5 | tail -n 1) \
[[ "$(head -n 5 "$(workspaces.data.path)/mock_curl.txt" | tail -n 1)" \
== *"/my-product/my-image6 "* ]]
[[ $(cat $(workspaces.data.path)/mock_curl.txt | head -n 6 | tail -n 1) \
[[ "$(tail -n 1 "$(workspaces.data.path)/mock_curl.txt")" \
== *"/id/5 "* ]]

EXPECTED_RESULTS='my-product/my-image5
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ spec:
- name: setup-values
image: quay.io/konflux-ci/release-service-utils:e633d51cd41d73e4b3310face21bb980af7a662f
script: |
#!/usr/bin/env sh
#!/usr/bin/env bash
set -eux

mkdir "$(workspaces.data.path)"/results

cat > $(workspaces.data.path)/snapshot_spec.json << EOF
cat > "$(workspaces.data.path)/snapshot_spec.json" << EOF
{
"application": "my-app",
"components": [
Expand All @@ -37,7 +37,7 @@ spec:
}
EOF

cat > $(workspaces.data.path)/data.json << EOF
cat > "$(workspaces.data.path)/data.json" << EOF
{
"pyxis": {
"skipRepoPublishing": "true"
Expand Down Expand Up @@ -72,12 +72,12 @@ spec:
- name: check-result
image: quay.io/konflux-ci/release-service-utils:e633d51cd41d73e4b3310face21bb980af7a662f
script: |
#!/usr/bin/env sh
#!/usr/bin/env bash
set -eux

if [ "$(wc -l < "$(workspaces.data.path)/mock_curl.txt")" != 1 ]; then
echo Error: curl was expected to be called once. Actual calls:
cat $(workspaces.data.path)/mock_curl.txt
cat "$(workspaces.data.path)/mock_curl.txt"
exit 1
fi

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ spec:
- name: setup-values
image: quay.io/konflux-ci/release-service-utils:e633d51cd41d73e4b3310face21bb980af7a662f
script: |
#!/usr/bin/env sh
#!/usr/bin/env bash
set -eux

mkdir "$(workspaces.data.path)"/results

cat > $(workspaces.data.path)/snapshot_spec.json << EOF
cat > "$(workspaces.data.path)/snapshot_spec.json" << EOF
{
"application": "my-app",
"components": [
Expand All @@ -37,7 +37,7 @@ spec:
}
EOF

cat > $(workspaces.data.path)/data.json << EOF
cat > "$(workspaces.data.path)/data.json" << EOF
{
"mapping": {
"defaults": {
Expand Down Expand Up @@ -74,20 +74,20 @@ spec:
- name: check-result
image: quay.io/konflux-ci/release-service-utils:e633d51cd41d73e4b3310face21bb980af7a662f
script: |
#!/usr/bin/env sh
#!/usr/bin/env bash
set -eux

if [ $(cat $(workspaces.data.path)/mock_curl.txt | wc -l) != 2 ]; then
if [ "$(wc -l < "$(workspaces.data.path)/mock_curl.txt")" != 2 ]; then
echo Error: curl was expected to be called 2 times. Actual calls:
cat $(workspaces.data.path)/mock_curl.txt
cat "$(workspaces.data.path)/mock_curl.txt"
exit 1
fi

[[ $(cat $(workspaces.data.path)/mock_curl.txt | head -n 1) \
[[ "$(head -n 1 "$(workspaces.data.path)/mock_curl.txt")" \
== *"/my-product/my-image1 "* ]]
[[ $(cat $(workspaces.data.path)/mock_curl.txt | tail -n 1) \
[[ "$(tail -n 1 "$(workspaces.data.path)/mock_curl.txt")" \
== *"/id/1 "* ]]
[[ $(cat $(workspaces.data.path)/mock_curl.txt | tail -n 1) \
[[ "$(tail -n 1 "$(workspaces.data.path)/mock_curl.txt")" \
!= *'{"source_container_image_enabled":true}' ]]
runAfter:
- run-task
Loading
Loading