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

ci: streamline test workflow #110

Merged
merged 4 commits into from
Oct 5, 2024
Merged
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
16 changes: 5 additions & 11 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ on:
# Reference: https://dev.to/petrsvihlik/using-environment-protection-rules-to-secure-secrets-when-building-external-forks-with-pullrequesttarget-hci
pull_request_target:
branches: [ main ]
push:
branches: [ main ]
merge_group:
jobs:
approve:
Expand Down Expand Up @@ -45,15 +43,11 @@ jobs:

steps:
# Checkout either the PR or the branch
- name: Checkout PR
if: ${{ github.event_name == 'pull_request_target' }}
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }} # Check out the code of the PR. Only after the manual approval process

- name: Checkout
uses: actions/checkout@v4
if: ${{ github.event_name != 'pull_request_target' }}
with:
ref: ${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || '' }}
fetch-depth: 0

- uses: reubenmiller/setup-go-c8y-cli@main
- name: install c8y-tedge extension
Expand Down Expand Up @@ -106,7 +100,7 @@ jobs:
case "${{matrix.job.bootstrap}}" in
script)
just IMAGE=${{matrix.job.target}} prepare-up
just IMAGE=${{matrix.job.target}} up
just IMAGE=${{matrix.job.target}} up --build=false
just IMAGE=${{matrix.job.target}} bootstrap --no-prompt
;;

Expand All @@ -127,7 +121,7 @@ jobs:

*)
just IMAGE=${{matrix.job.target}} prepare-up
just IMAGE=${{matrix.job.target}} up
just IMAGE=${{matrix.job.target}} up --build=false
echo "Skipping bootstrapping"
;;
esac
Expand Down
41 changes: 1 addition & 40 deletions images/alpine-s6/bootstrap.sh
Original file line number Diff line number Diff line change
@@ -1,44 +1,5 @@
#!/bin/sh
set -e

SHOULD_PROMPT=${SHOULD_PROMPT:-1}
CAN_PROMPT=0

#
# Detect if the shell is running in interactive mode or not
if [ -t 0 ]; then
CAN_PROMPT=1
else
CAN_PROMPT=0
fi

prompt_value() {
user_text="$1"
value="$2"

if [ "$SHOULD_PROMPT" = 1 ] && [ "$CAN_PROMPT" = 1 ]; then
printf "\n%s (%s): " "$user_text" "${value:-not set}" >&2
read -r user_input
if [ -n "$user_input" ]; then
value="$user_input"
fi
fi
echo "$value"
}

if [ -z "$TEDGE_MQTT_DEVICE_TOPIC_ID" ]; then
if [ -z "$C8Y_USER" ]; then
C8Y_USER=$(prompt_value "Enter your Cumulocity IoT user" "$C8Y_USER")
fi

if [ -z "$C8Y_USER" ]; then
echo "C8Y_USER is not set"
exit 1
fi

if [ -n "$C8Y_PASSWORD" ]; then
C8YPASS="$C8Y_PASSWORD" tedge cert upload c8y --user "$C8Y_USER"
else
tedge cert upload c8y --user "$C8Y_USER"
fi
tedge cert upload c8y
fi
2 changes: 1 addition & 1 deletion images/alpine-s6/mosquitto/mosquitto-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ fi
#
# Upload cert if credentials are available
if [ -n "$C8Y_PASSWORD" ] && [ -n "$C8Y_USER" ]; then
env C8YPASS="$C8Y_PASSWORD" tedge cert upload c8y --user "$C8Y_USER" ||:
tedge cert upload c8y --user "$C8Y_USER" ||:
fi

# Wait until the device has been registered before starting the bridge,
Expand Down
15 changes: 2 additions & 13 deletions images/common/bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -332,19 +332,8 @@ bootstrap_c8y() {
echo "Setting c8y.url to $C8Y_BASEURL"
sudo tedge config set c8y.url "$C8Y_BASEURL"

C8Y_USER=$(prompt_value "Enter your Cumulocity user" "$C8Y_USER")

if [ -n "$C8Y_USER" ]; then
echo "Uploading certificate to Cumulocity using tedge"
if [ -n "$C8Y_PASSWORD" ]; then
C8YPASS="$C8Y_PASSWORD" tedge cert upload c8y --user "$C8Y_USER"
else
echo ""
tedge cert upload c8y --user "$C8Y_USER"
fi
else
fail "When manually bootstrapping you have to upload the certificate again as the device certificate is recreated"
fi
echo "Uploading certificate to Cumulocity using tedge"
tedge cert upload c8y

# Grace period for the server to process the certificate
# but it is not critical for the connection, as the connection
Expand Down