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

Make a proper Log class and methods #948

Open
wants to merge 36 commits into
base: v5
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
a285c80
Brainstorm log goals and architecture
plocket Aug 13, 2024
3f98f14
Implement draft of log.verbose() and
plocket Aug 15, 2024
f54bb43
Implement and lightly test basic log methods
plocket Aug 16, 2024
6b669cd
Start replacing `log` with `Log`
plocket Aug 17, 2024
4435bff
Append to files, add error checking and fallbacks
plocket Aug 19, 2024
3f05ff1
Untested: make artifacts folder, add info logs, also
plocket Aug 23, 2024
8e7e115
Update decisions, alias waiting, tweak logs
plocket Aug 23, 2024
0feaa11
Implement new log interface for setup, run, takedown, da api,
plocket Aug 26, 2024
c2f9e9a
Implement new log signature in all necessary files
plocket Aug 28, 2024
b6b5450
Add logs decision doc, remove success rainbow from action
plocket Sep 6, 2024
5fbe276
Change log methods signature, use fs.append, add stdout...
plocket Sep 6, 2024
9f4db4e
Fix workflow typos, remove ALK0000, add TODOs, edit decision docs
plocket Sep 7, 2024
ed36ec4
Add logging to actions
plocket Sep 9, 2024
5a9c436
Create folder and paths for log tests, file creation handles path
plocket Sep 17, 2024
a26740a
Brainstorm and refactor to do calcs in .debug(). Also,
plocket Sep 17, 2024
a3ee8cd
Refactor formatting, add tests, clean up
plocket Sep 30, 2024
55391a0
Brainstorm about categories of errors, add notes, refactor, add
plocket Oct 5, 2024
9f3de78
Remove explicitly writing to unexpected, note about writing to
plocket Oct 6, 2024
d97add8
Only allow `error` on throw, warn of misuse, make
plocket Oct 6, 2024
6d9ff35
Join stdout args with no spaces. Brainstorm class signature with
plocket Oct 8, 2024
53904e4
Tweak name, add function descriptions, comments, and examples
plocket Oct 13, 2024
7fea6d1
Refactor getting errors, protect against infinite loops...
plocket Oct 15, 2024
d8be814
Refactor deep methods for getting safe error
plocket Oct 16, 2024
5df8518
Save both report and debug info to the unexpected results file
plocket Oct 16, 2024
303a5dd
Simplify use of `context` in wrapper functionality as per review
plocket Oct 17, 2024
68131e1
Add and edit decision docs, notes, and TODOs
plocket Oct 18, 2024
92ed70d
Abstract util.inspect()
plocket Oct 28, 2024
fd62483
Refactor to avoid internal circular calls of `.debug()`
plocket Oct 29, 2024
9589791
Implement some TODOs and clean up
plocket Oct 30, 2024
59a416a
Make internal-specific icon and level, as per PR comment:
plocket Oct 30, 2024
9935469
Reformat and deduplicate reports, clarify var names
plocket Nov 1, 2024
36e06a0
Continue work on documentation of logs architecture
plocket Nov 1, 2024
056bb5b
Rename doc about kinds of errors
plocket Nov 8, 2024
e99c20d
Modify artifact folder name diagrams, clarify diagrams
plocket Nov 8, 2024
435b412
Add to CHANGELOG, correct/add diagrams. Mermaid needs "o" hack.
plocket Nov 11, 2024
976d66e
Rename log.js to Log.js
plocket Nov 22, 2024
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: 8 additions & 8 deletions .github/workflows/github_server.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ jobs:
#### keyword or values at all. See
#### https://assemblyline.suffolklitlab.org/docs/alkiln/writing#env-vars
env:
NORMAL_USER_EMAIL: [email protected]
NORMAL_USER_PASSWORD: User123^
WRONG_EMAIL: [email protected]
WRONG_PASSWORD: wrong_password
INVALID_API_KEY: invalidAPIkey
EMPTY_STRING: ""
SECRET_VAR1: secret-var1-value
SECRET_VAR2: secret-var2-value
SECRET_FOR_MISSING_FIELD: secret for missing field
INVALID_API_KEY: invalidAPIkey
EMPTY_STRING: ""
NORMAL_USER_EMAIL: [email protected]
NORMAL_USER_PASSWORD: User123^
[email protected]
WRONG_PASSWORD=wrong_password

steps:
# Place the root directory in this branch to access
Expand Down Expand Up @@ -160,7 +160,7 @@ jobs:
#### Developer note: You can probably leave the rest out
#### To learn more, see https://assemblyline.suffolklitlab.org/docs/alkiln/writing/#optional-inputs
ALKILN_TAG_EXPRESSION: "${{ env.ALKILN_TAG_EXPRESSION }}"
ALKILN_VERSION: delete
ALKILN_VERSION: logs

#### Developer note: Example of making an issue when tests fail
#### that includes the text of the failure output file
Expand All @@ -169,7 +169,7 @@ jobs:
if: ${{ failure() }}
env:
GH_TOKEN: ${{ github.token }}
PATH_TO_REPORT_FILE: "${{ steps.alkiln.outputs.PATH_TO_REPORT_FILE }}"
PATH_TO_REPORT_LOG_FILE: "${{ steps.alkiln.outputs.PATH_TO_REPORT_LOG_FILE }}"
PATH_TO_UNEXPECTED_RESULTS_FILE: "${{ steps.alkiln.outputs.PATH_TO_UNEXPECTED_RESULTS_FILE }}"
PATH_TO_DEBUG_LOG_FILE: "${{ steps.alkiln.outputs.PATH_TO_DEBUG_LOG_FILE }}"
run: |
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/playground.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ jobs:
NORMAL_USER_PASSWORD: ${{ secrets.USER_NO_PERMISSIONS_PASSWORD }}
NORMAL_USER_API_KEY: ${{ secrets.USER_NO_PERMISSIONS_API_KEY }}
INVALID_API_KEY: invalidAPIkey
WRONG_EMAIL=[email protected]
WRONG_PASSWORD=wrong_password
WRONG_EMAIL: [email protected]
WRONG_PASSWORD: wrong_password
EMPTY_STRING: ""
SECRET_VAR1: secret-var1-value
SECRET_VAR2: secret-var2-value
Expand Down Expand Up @@ -81,4 +81,4 @@ jobs:
# want to check up on this.
ALKILN_TAG_EXPRESSION: "${{ env.ALKILN_TAG_EXPRESSION }}"
#### Developer note: You can probably leave this out
ALKILN_VERSION: delete
ALKILN_VERSION: logs
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ Format:
### Fixed

- Detects failed sign in. Closes [#918](https://github.com/SuffolkLITLab/ALKiln/issues/918).
- Fixes undefined `errors` var in `After()`
- Closes [#924](https://github.com/SuffolkLITLab/ALKiln/issues/924), remove extra interview url print

### Internal

Expand All @@ -62,6 +64,10 @@ Format:
- Adds decision docs
- Updated CONTRIBUTING.md
- Added example.env, closes [#374](https://github.com/SuffolkLITLab/ALKiln/issues/374)
- Closes [#805](https://github.com/SuffolkLITLab/ALKiln/issues/805), create verbose-type log
- Closes [#659](https://github.com/SuffolkLITLab/ALKiln/issues/659), abstract adding to debug_log
- Closes [#925](https://github.com/SuffolkLITLab/ALKiln/issues/925), allow a `Log` to throw an error
- Addresses [#461](https://github.com/SuffolkLITLab/ALKiln/issues/461), setup and takedown reports

## [5.13.0] - 2024-07-11

Expand Down
98 changes: 70 additions & 28 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ outputs:
PATH_TO_REPORT_FILE:
description: 'An empty string ("") or the path to report.txt. Remember to check for the existence of the file before using it.'
value: ${{ steps.alkiln_outputs.outputs.PATH_TO_REPORT_FILE }}
PATH_TO_REPORT_LOG_FILE:
description: 'An empty string ("") or the path to report_log.txt. Remember to check for the existence of the file before using it.'
value: ${{ steps.alkiln_outputs.outputs.PATH_TO_REPORT_LOG_FILE }}
PATH_TO_UNEXPECTED_RESULTS_FILE:
description: 'An empty string ("") or the path to unexpected_results.txt. Remember to check for the existence of the file before using it.'
value: ${{ steps.alkiln_outputs.outputs.PATH_TO_UNEXPECTED_RESULTS_FILE }}
Expand All @@ -67,9 +70,20 @@ runs:
DOCASSEMBLECLI_VERSION: ${{ inputs.DOCASSEMBLECLI_VERSION }}
shell: bash
run: |
# 💡 ALK0023 INFO: Set environment variables
log="💡 ALK0023 INFO: Set environment variables and create artifacts folder"

# Human-readable date/time: https://www.shell-tips.com/linux/how-to-format-date-and-time-in-linux-macos-and-bash/#how-to-format-a-date-in-bash
echo "ARTIFACT_NAME=alkiln-$(date +'%Y-%m-%d at %Hh%Mm%Ss' -u)UTC" >> $GITHUB_ENV
timestamp="$(date +'%Y-%m-%d at %Hh%Mm%Ss' -u)"
artifact_folder="alkiln-${timestamp}UTC"
debug_path="${artifact_folder}/debug_log.txt"
mkdir -p "$artifact_folder"
echo "$log" >> "$debug_path"

# Action-specific vars
echo "ARTIFACT_FOLDER=$artifact_folder" >> $GITHUB_ENV
echo "DEBUG_PATH=$debug_path" >> $GITHUB_ENV

# Required for all tests
echo "REPO_URL=${{ github.server_url }}/${{ github.repository }}" >> $GITHUB_ENV
echo "BRANCH_PATH=$BRANCH_PATH" >> $GITHUB_ENV
# Workflow inputs
Expand All @@ -84,18 +98,21 @@ runs:
- name: "💡 ALK0024 INFO: Confirm environment variables"
shell: bash
run: |
# 💡 ALK0024 INFO: Confirm environment variables
echo -e "\nALKiln version is $ALKILN_VERSION\nRepo is $REPO_URL\nBranch ref is $BRANCH_PATH\nMAX_SECONDS_FOR_SETUP is $MAX_SECONDS_FOR_SETUP\nSERVER_RELOAD_TIMEOUT_SECONDS is $SERVER_RELOAD_TIMEOUT_SECONDS\n"
log="💡 ALK0024 INFO: Confirm environment variables"
echo -e "\n$log" >> "${{ env.DEBUG_PATH }}"
vars_log="\nALKiln version is $ALKILN_VERSION\nRepo is $REPO_URL\nBranch ref is $BRANCH_PATH\nMAX_SECONDS_FOR_SETUP is $MAX_SECONDS_FOR_SETUP\nSERVER_RELOAD_TIMEOUT_SECONDS is $SERVER_RELOAD_TIMEOUT_SECONDS\n"
echo -e "$vars_log" >> "${{ env.DEBUG_PATH }}" && echo -e "$vars_log"

# Install
- name: "💡 ALK0025 INFO: Install node packages"
- name: "💡 ALK0025 INFO: Set up node"
uses: actions/setup-node@v4
with:
node-version: "18"
- name: "💡 ALK0026 INFO: Install ALKiln directly from npm"
shell: bash
run: |
# 💡 ALK0026 INFO: Install ALKiln directly from npm
log="💡 ALK0026 INFO: Install ALKiln directly from npm"
echo -e "\n$log" >> "${{ env.DEBUG_PATH }}"
npm install -g "@suffolklitlab/alkiln@$ALKILN_VERSION"

# Install on playground
Expand All @@ -109,100 +126,124 @@ runs:
if: ${{ inputs.INSTALL_METHOD == 'playground' }}
shell: bash
run: |
# 💡 ALK0027 INFO: Create a Project and install the package from GitHub
log="💡 ALK0027 INFO: Create a Project and install the package from GitHub"
echo -e "\n$log" >> "${{ env.DEBUG_PATH }}"
pip install "docassemblecli==$DOCASSEMBLECLI_VERSION"
alkiln-setup
- name: "😞 ALK0028 ERROR: Unable to create a Project"
alkiln-setup --path="${{ env.ARTIFACT_FOLDER }}"
- name: "🤕 ALK0028 ERROR: Unable to create a Project"
if: ${{ inputs.INSTALL_METHOD == 'playground' && failure() }}
shell: bash
run: |
# 😞 ALK0028 ERROR: Unable to create a Project
echo -e "\n\n====\n😞 ALK0028 ERROR: Unable to create a Project on your server's testing account or pull your package into it. Check the messages above this line.\n\n"
# "🤕 ALK0028 ERROR: Unable to create a Project"
long_log="\n\n―――\n🤕 ALK0028 ERROR: Unable to create a Project on your server's testing account or pull your package into it. Check the messages above this line.\n\n"
echo -e "$long_log" >> "${{ env.DEBUG_PATH }}" && echo -e "$long_log"

# Server installations - find folders and save session vars
- name: "💡 ALK0029 INFO: Install the GitHub package onto the server"
if: ${{ inputs.INSTALL_METHOD == 'server' }}
shell: bash
run: alkiln-server-install
- name: "😞 ALK0030 ERROR: Unable to install the package"
run: |
log="💡 ALK0029 INFO: Install the GitHub package onto the server"
echo -e "\n$log" >> "${{ env.DEBUG_PATH }}"
alkiln-server-install --path="${{ env.ARTIFACT_FOLDER }}"
- name: "🤕 ALK0030 ERROR: Unable to install the package"
if: ${{ inputs.INSTALL_METHOD == 'server' && failure() }}
shell: bash
run: |
echo -e "\n\n====\n😞 ALK0030 ERROR: Unable to install the package on the temporary GitHub docassemble server. Check the steps above this line.\n\n"
log="\n\n―――\n🤕 ALK0030 ERROR: Unable to install the package on the temporary GitHub docassemble server. Check the steps above this line.\n\n"
echo -e "$log" >> "${{ env.DEBUG_PATH }}" && echo -e "$log"

# run tests
- name: "💡 ALK0031 INFO: Run tests"
if: ${{ success() }}
env:
ALKILN_TAG_EXPRESSION: ${{ inputs.ALKILN_TAG_EXPRESSION || github.event.inputs.tags && format('{0}', github.event.inputs.tags) }}
shell: bash
run: alkiln-run "$ALKILN_TAG_EXPRESSION"
run: |
log="💡 ALK0031 INFO: Run tests"
echo -e "\n$log" >> "${{ env.DEBUG_PATH }}"
alkiln-run "$ALKILN_TAG_EXPRESSION" --path="${{ env.ARTIFACT_FOLDER }}"

# on playground, delete project
- name: "💡 ALK0032 INFO: Delete the Project from the Playground"
if: ${{ always() && inputs.INSTALL_METHOD == 'playground' }}
run: alkiln-takedown
shell: bash
run: |
log="💡 ALK0032 INFO: Delete the Project from the Playground"
echo -e "\n$log" >> "${{ env.DEBUG_PATH }}"
alkiln-takedown --path="${{ env.ARTIFACT_FOLDER }}"

# Upload artifacts that subscribers can download on the Actions summary page
- name: "💡 ALK0033 INFO: Upload artifacts folder"
if: ${{ always() }}
uses: actions/upload-artifact@v4
with:
name: ${{ env.ARTIFACT_NAME }}
name: ${{ env.ARTIFACT_FOLDER }}
path: ./alkiln-*

# Download artifacts folder internally to create action output
- name: "💡 ALK0183 INFO: Get uploaded artifacts folder"
if: ${{ always() }}
uses: actions/download-artifact@v4
with:
name: ${{ env.ARTIFACT_NAME }}
name: ${{ env.ARTIFACT_FOLDER }}

- name: "💡 ALK0184 INFO: Prepare ALKiln output file paths"
if: ${{ always() }}
id: alkiln_outputs
shell: bash
run: |
# 💡 ALK0184 INFO: Prepare ALKiln output file paths
log="💡 ALK0184 INFO: Prepare ALKiln output file paths"
echo -e "\n$log" >> "${{ env.DEBUG_PATH }}" && echo "$log"

FOLDER=$(ls -d */ | grep -E '^alkiln-*' || true)

echo "Test results artifacts folder is $FOLDER"
log_folder="Test results artifacts folder is $FOLDER"
echo -e "\n$log_folder" >> "${{ env.DEBUG_PATH }}" && echo "$log_folder"

if [[ "$FOLDER" = "" ]]; then
echo "Artifacts folder is missing. The path is an empty string: '$FOLDER'"
log_missing="Artifacts folder is missing. The path is an empty string: '$FOLDER'"
echo -e "\n$log_missing" >> "${{ env.DEBUG_PATH }}" && echo "$log_missing"

else
REPORT_PATH="${FOLDER}report.txt"
REPORT_LOG_PATH="${FOLDER}report_log.txt"
UNEXPECTED_RESULTS_PATH="${FOLDER}unexpected_results.txt"
DEBUG_LOG_PATH="${FOLDER}debug_log.txt"

if [ -f "$REPORT_PATH" ]; then
echo "$REPORT_PATH exists"
echo -e "\n$REPORT_PATH exists" >> "${{ env.DEBUG_PATH }}" && echo "$REPORT_PATH exists"
else
echo "$REPORT_PATH is missing"
echo -e "\n$REPORT_PATH is missing" >> "${{ env.DEBUG_PATH }}" && echo "$REPORT_PATH is missing"
REPORT_PATH=""
fi

if [ -f "$REPORT_LOG_PATH" ]; then
echo -e "\n$REPORT_LOG_PATH exists" >> "${{ env.DEBUG_PATH }}" && echo "$REPORT_LOG_PATH exists"
else
echo -e "\n$REPORT_LOG_PATH is missing" >> "${{ env.DEBUG_PATH }}" && echo "$REPORT_LOG_PATH is missing"
REPORT_LOG_PATH=""
fi

if [ -f "$UNEXPECTED_RESULTS_PATH" ]; then
echo "$UNEXPECTED_RESULTS_PATH exists"
echo -e "\n$UNEXPECTED_RESULTS_PATH exists" >> "${{ env.DEBUG_PATH }}" && echo "$UNEXPECTED_RESULTS_PATH exists"
else
echo "$UNEXPECTED_RESULTS_PATH is missing"
echo -e "\n$UNEXPECTED_RESULTS_PATH is missing" >> "${{ env.DEBUG_PATH }}" && echo "$UNEXPECTED_RESULTS_PATH is missing"
UNEXPECTED_RESULTS_PATH=""
fi

if [ -f "$DEBUG_LOG_PATH" ]; then
echo "$DEBUG_LOG_PATH exists"
echo -e "\n$DEBUG_LOG_PATH exists" >> "${{ env.DEBUG_PATH }}" && echo "$DEBUG_LOG_PATH exists"
else
echo "$DEBUG_LOG_PATH is missing"
echo -e "\n$DEBUG_LOG_PATH is missing" >> "${{ env.DEBUG_PATH }}" && echo "$DEBUG_LOG_PATH is missing"
DEBUG_LOG_PATH=""
fi

fi

echo "PATH_TO_ARTIFACTS=$FOLDER" >> "$GITHUB_OUTPUT"
echo "PATH_TO_REPORT_FILE=$REPORT_PATH" >> "$GITHUB_OUTPUT"
echo "PATH_TO_REPORT_LOG_FILE=$REPORT_LOG_PATH" >> "$GITHUB_OUTPUT"
echo "PATH_TO_UNEXPECTED_RESULTS_FILE=$UNEXPECTED_RESULTS_PATH" >> "$GITHUB_OUTPUT"
echo "PATH_TO_DEBUG_LOG_FILE=$DEBUG_LOG_PATH" >> "$GITHUB_OUTPUT"

Expand All @@ -212,4 +253,5 @@ runs:
- shell: bash
if: ${{ always() }}
run: |
echo "💡 ALK0034 INFO: ALkiln finished running tests"
log="💡 ALK0034 INFO: ALkiln finished running tests. See above for more details."
echo -e "\n$log" >> "${{ env.DEBUG_PATH }}" && echo "$log"
Loading
Loading