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

internal: fix and improve get-logs GitHub workflow #2201

Merged
merged 10 commits into from
Oct 29, 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
19 changes: 13 additions & 6 deletions .github/workflows/get-logs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,15 @@ on:
- 'indev'
default: 'indev'
grep-arg:
description: 'Grep argument'
required: true
description: 'Filter (grep)'
required: false
type: string
default: ''
tail:
description: 'Num of lines to check (tail)'
required: true
type: string
default: '10000'

jobs:
get-logs:
Expand All @@ -28,24 +33,26 @@ jobs:
run: |
echo "DEPLOY_BRANCH=${{ github.event.inputs.branch }}" >> $GITHUB_ENV
echo "GREP_ARG=${{ github.event.inputs.grep-arg }}" >> $GITHUB_ENV
echo "TAIL_ARG=${{ github.event.inputs.tail }}" >> $GITHUB_ENV

- name: Set up repository_dispatch inputs
if: github.event_name == 'repository_dispatch'
run: |
echo "Received Payload:"
echo "${{ github.event.client_payload.inputs.branch }}"
echo "${{ github.event.client_payload.inputs.grep-arg }}"
echo "${{ github.event.client_payload.inputs.tail }}"

echo "DEPLOY_BRANCH=${{ github.event.client_payload.inputs.branch }}" >> $GITHUB_ENV
echo "GREP_ARG=${{ github.event.client_payload.inputs.grep-arg }}" >> $GITHUB_ENV
echo "TAIL_ARG=${{ github.event.client_payload.inputs.tail }}" >> $GITHUB_ENV

- name: Checkout
- name: Checkout misc/deploy folder
uses: actions/checkout@v4
with:
submodules: recursive
fetch-depth: 0
fetch-depth: 1

- name: Deploy
- name: Get logs from server
env:
DEPLOY_TARGET_HOST: ${{secrets.DEPLOY_TARGET_HOST_06_2024}}
DEPLOY_TARGET_USER: ${{secrets.DEPLOY_TARGET_USER_06_2024}}
Expand Down
11 changes: 3 additions & 8 deletions misc/deploy/get_logs_from_server.sh
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
#!/usr/bin/env bash

report_fail() {
./misc/deploy/call_webhook.sh "Something went wrong, please see GitHub logs for details"
exit 1
}
trap report_fail ERR

# cheatsheet: https://stackoverflow.com/a/44606194
# ? without : accepts empty string
# Ensuring all required variables are set:
echo "${DEPLOY_TARGET_HOST:?}" > /dev/null
echo "${DEPLOY_TARGET_USER:?}" > /dev/null
echo "${GREP_ARG:?}" > /dev/null
echo "${GREP_ARG?}" > /dev/null # OK to be empty
echo "${TAIL_ARG:?}" > /dev/null
echo "${DEPLOY_BRANCH:?}" > /dev/null
echo "${DEPLOY_SSH_PRIVATE_KEY:?}" > /dev/null
echo "${DEPLOY_SSH_KNOWN_HOSTS:?}" > /dev/null
Expand Down Expand Up @@ -39,4 +34,4 @@ remote_branch_dir="skymp-server-$DEPLOY_BRANCH"
run_remote test -e "$remote_branch_dir" \
|| (echo "no branch on remote server" && exit 1)

run_remote bash -c "docker logs --tail 100 $remote_branch_dir | grep $GREP_ARG"
run_remote "bash -c 'docker logs --tail $TAIL_ARG \"$remote_branch_dir\" | grep \"$GREP_ARG\"'"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Variables should be quoted to handle spaces or special characters correctly.

Suggested change
run_remote "bash -c 'docker logs --tail $TAIL_ARG \"$remote_branch_dir\" | grep \"$GREP_ARG\"'"
run_remote "bash -c 'docker logs --tail "$TAIL_ARG" "$remote_branch_dir" | grep "$GREP_ARG"'"

Loading