Skip to content

Commit

Permalink
Refactor action.yml to set working directory before script execution (#…
Browse files Browse the repository at this point in the history
…11)

* Refactor action.yml to set working directory before script execution

* Remove unnecessary directory changes in action.yml and copy script to workspace

* Remove caching of npm dependencies and update installation command in action.yml

* try to use dist

* Meh

* move http-server into action

* add required shell keywords

* cp: '/home/runner/work/webapp-console-log-action/webapp-console-log-action/.//dist' and './dist' are the same file

* run common JS on the fly

* remove path

* try to execute capture script directly without transforming to CJS

* remove unnecessary packages

* create index html file on the fly

* debug file outputs

* use weird suggestion from Github Copilot to access the file

* get the artifact inside the action

* remove debug steps

* Revert "remove debug steps"

This reverts commit 29d8e53.

* add debug steps back

* set working directory

* set working directory

* list directories

* change directories while running

* debug cd

* cd has actually no effect!!

* syntax

* syntax

* store action path

* use stored path

* remove debug

* add port and tests

* checkout

* read port from env not from input

* pass the fails if the fail fails successfully 😅

* fi

* continue-on-error

* check step instead of job

* it's outcome not status

* update README.md
  • Loading branch information
Primajin authored Jan 8, 2025
1 parent 503495a commit 353e27d
Show file tree
Hide file tree
Showing 13 changed files with 522 additions and 338 deletions.
73 changes: 73 additions & 0 deletions .github/workflows/fail_all-defaults.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
name: "Negative Test - all defaults"

on:
pull_request:
types:
- opened
- reopened
- synchronize
- closed

permissions:
pull-requests: write

jobs:
fail:
runs-on: ubuntu-latest
name: Should fail - has warnings and errors, uses all defaults
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Create fake App with console outputs
run: |
touch index.html
cat > index.html << EOF

<!DOCTYPE html>
<html>
<head>
<title>New Page</title>
</head>
<body>
<h1>Hello, World!</h1>
<script>
console.debug('This is a debug message and likely hidden in the fail workflow');
console.info('This is an info in the fail workflow');
console.log('This is a log in the fail workflow');
console.log('This is another log in the fail workflow');
console.warn('This is a warning in the fail workflow');
console.error('This is an error in the fail workflow');
</script>
</body>
</html>

EOF

- name: Upload index.html
uses: actions/upload-artifact@v4
with:
name: index-html
path: index.html

- name: Use WebApp Console Log Action
id: webapp_console_log
uses: ./
with:
artifact-name: index-html
webapp-url: 'http://localhost'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
continue-on-error: true

- name: Check previous step result and set job result
if: always()
run: |
if [ "${{ steps.webapp_console_log.outcome }}" == "failure" ]; then
echo "Previous step failed as expected, marking job as success"
exit 0
else
echo "Previous step did not fail, failing the job"
exit 1
fi
40 changes: 40 additions & 0 deletions .github/workflows/fail_missing-artifact-name.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: "Negative Test - missing artifact name"

on:
pull_request:
types:
- opened
- reopened
- synchronize
- closed

permissions:
pull-requests: write

jobs:
fail:
runs-on: ubuntu-latest
name: Should fail early - has localhost but no artifact name
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Use WebApp Console Log Action
id: webapp_console_log
uses: ./
with:
webapp-url: 'http://localhost'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
continue-on-error: true

- name: Check previous step result and set job result
if: always()
run: |
if [ "${{ steps.webapp_console_log.outcome }}" == "failure" ]; then
echo "Previous step failed as expected, marking job as success"
exit 0
else
echo "Previous step did not fail, failing the job"
exit 1
fi
67 changes: 67 additions & 0 deletions .github/workflows/pass-all.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: "Positive Test - all parameters set"

on:
pull_request:
types:
- opened
- reopened
- synchronize
- closed

permissions:
pull-requests: write

jobs:
pass:
runs-on: ubuntu-latest
name: Should pass - has all parameters set
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Create fake App with console outputs
run: |
touch index.html
cat > index.html << EOF
<!DOCTYPE html>
<html>
<head>
<title>New Page</title>
</head>
<body>
<h1>Hello, World!</h1>
<script>
console.debug('This is a debug message and likely hidden in the pass workflow');
console.info('This is an info in the pass workflow');
console.log('This is a log in the pass workflow');
console.log('This is another log in the pass workflow');
console.warn('This is a warning in the pass workflow');
console.error('This is an error in the pass workflow');
</script>
</body>
</html>
EOF
- name: Upload index.html
uses: actions/upload-artifact@v4
with:
name: index-html
path: index.html

- name: Use WebApp Console Log Action
uses: ./
with:
artifact-name: index-html
comment-tag: console-log2
headline: No emojis, min log level warning, max log level error
max-log-level: error
min-log-level: warning
port: 3001
show-emoji: false
wait-time: 5
webapp-url: 'http://localhost'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
65 changes: 65 additions & 0 deletions .github/workflows/pass-localhost-no-port.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: "Positive Test - has localhost but no port"

on:
pull_request:
types:
- opened
- reopened
- synchronize
- closed

permissions:
pull-requests: write

jobs:
pass:
runs-on: ubuntu-latest
name: Should pass - has localhost but no port
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Create fake App with console outputs
run: |
touch index.html
cat > index.html << EOF
<!DOCTYPE html>
<html>
<head>
<title>New Page</title>
</head>
<body>
<h1>Hello, World!</h1>
<script>
console.debug('This is a debug message and likely hidden in the pass workflow');
console.info('This is an info in the pass workflow');
console.log('This is a log in the pass workflow');
console.log('This is another log in the pass workflow');
console.warn('This is a warning in the pass workflow');
console.error('This is an error in the pass workflow');
</script>
</body>
</html>
EOF
- name: Upload index.html
uses: actions/upload-artifact@v4
with:
name: index-html
path: index.html

- name: Use WebApp Console Log Action
uses: ./
with:
artifact-name: index-html
comment-tag: console-log3
headline: Should pass - has localhost but no port
max-log-level: error
min-log-level: warning
wait-time: 5
webapp-url: 'http://localhost'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: "Negative Test"
name: "Positive Test - uses external URL"

on:
pull_request:
Expand All @@ -12,18 +12,18 @@ permissions:
pull-requests: write

jobs:
build:
pass:
runs-on: ubuntu-latest
name: Should fail - Install a server and serve a file with console logs. Then post console to PR.
name: Should pass - uses external url
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Run http-server on port 3000 in the background
run: npx http-server ./ -p 3000 &

- name: Use WebApp Console Log Action
uses: ./
with:
wait-time: 5
webapp-url: 'http://localhost:3000'
comment-tag: console-log4
headline: External - Eyesbound.com
webapp-url: 'https://eyesbound.com'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
34 changes: 0 additions & 34 deletions .github/workflows/should-pass.yml

This file was deleted.

2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
Expand Down
Loading

0 comments on commit 353e27d

Please sign in to comment.