Skip to content

Commit

Permalink
feat: GitHub pages
Browse files Browse the repository at this point in the history
  • Loading branch information
cybersokari committed Jan 14, 2025
1 parent b6ba2ff commit d167b07
Show file tree
Hide file tree
Showing 8 changed files with 156 additions and 48 deletions.
13 changes: 13 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Mandatory inputs
INPUT_GOOGLE_CREDENTIALS_JSON={}
INPUT_ALLURE_RESULTS_PATH=/github/workspace/test-results

# Optional inputs
#INPUT_OUTPUT=output-directory
INPUT_REPORT_NAME='Example Report'
INPUT_STORAGE_BUCKET=example-bucket
INPUT_RETRIES=3
INPUT_SHOW_HISTORY=true
INPUT_SLACK_CHANNEL=C1234567890
INPUT_SLACK_TOKEN=xoxb-1234567890-0987654321
INPUT_PREFIX=example-prefix
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

.idea
allure-deployer-action.iml
allure-deployer-action.iml
.env
11 changes: 11 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM node:20-alpine AS deps
LABEL authors="cybersokari"
RUN apk add --no-cache openjdk17-jre

FROM deps AS prod

RUN npm i -g [email protected]
COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh

ENTRYPOINT ["/entrypoint.sh"]
28 changes: 28 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
BSD 3-Clause License

Copyright (c) 2024, Sokari Gillis-Harry

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
54 changes: 24 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,22 @@ No server required.**


## 🛠️ Inputs
| Input Name | Description | Required | Default |
|-----------------------|---------------------------------------------------------------------------------------------------------------|----------|---------------|
| `storage_bucket` | Google Cloud Storage bucket name. | No | None |
| `report_name` | The name/title of your report. | No | Allure Report |
| `slack_channel` | Slack channel ID | No | None |
| `allure_results_path` | Directory containing Allure results. | Yes | None |
| `retries` | Number of previous test runs to show as retries in the new report when Storage `storage_bucket` is provided | No | `0` |
| `show_history` | Display historical data in the test report (`true/false`). | No | `true` |
| `update_pr` | Add report info as pr comment or actions summary (`comment`/`summary`) | No | `summary` |
| `output` | A directory to generate Allure report into. Setting this value disables report hosting and Slack notification | No | None |
| Input | Description | Required | Default |
|---------------------------|------------------------------------------------------------------------------------------------------------------|----------|-------------------|
| `google_credentials_json` | Firebase (Google Cloud) credentials JSON | Yes | None |
| `allure_results_path` | Path to the directory containing Allure results files. | Yes | `/allure-results` |
| `report_name` | The name/title of your report. | No | `Allure Report` |
| `storage_bucket` | Name of the Google Cloud Storage bucket for backup and history storage. | No | None |
| `prefix` | Path prefix in the Cloud Storage bucket for archiving files. | No | None |
| `show_history` | Display history from previous test runs. | No | `true` |
| `retries` | Number of previous test runs to show as retries in the upcoming report when Storage `storage_bucket` is provided | No | 0 |
| `output` | A directory to generate Allure report into. Setting this value disables report hosting and Slack notification | No | None |
| `slack_channel` | ID of the Slack channel to send notifications about report links. | No | None |
| `slack_token` | Token for Slack App to send notifications with report URLs. | No | None |
| `github_token` | A generated GITHUB_TOKEN for when `github_pages_branch` is provide or when `pr_comment` is set to `true` | No | None |
| `pr_comment` | Post test report information as pull request comment. Requires `github_token` to be set with permission | No | `false` |
| `github_pages_branch` | Set target branch for Deploying test report to GitHub Pages. Requires `github_token` to be set with permission | No | None |

## 🔧 Environment Variables
| Variable | Description | Required | Example |
|---------------------------|-------------------------------------------------------------------------------|----------|--------------------------------------|
| `GOOGLE_CREDENTIALS_JSON` | Firebase (Google Cloud) credentials JSON | Yes | `{ "type": "service_account", ... }` |
| `SLACK_TOKEN` | Slack Bot API token when `slack_channel` is set | No | `xoxb-****` |
| `GITHUB_TOKEN` | Github auth token for pull request updates if `update_pr` is set to `comment` | No | `ghp_*****` |

## 📤 Outputs
| Key | Description |
Expand All @@ -41,10 +40,8 @@ No server required.**
```yaml
name: Allure Report Deployer
on:
push:
branches:
- main
permissions: # For when `update_pr` is `comment`
pull_request:
permissions: # For when `pr_comment` is `true`
pull-requests: write
issues: write
jobs:
Expand All @@ -57,30 +54,27 @@ jobs:
Run test and create allure results
- name: Run Allure Report Deployer
uses: cybersokari/allure-deployer-action@v1.2
uses: cybersokari/allure-deployer-action@v1.4
with:
google_credentials_json: ${{ secrets.GCP_CREDENTIALS_JSON }}
allure_results_path: 'path/to/allure-results'
storage_bucket: 'your_bucket_name'
retries: 4
show_history: true
slack_channel: 'YOUR_SLACK_CHANNEL_ID'
update_pr: 'comment'
env:
GOOGLE_CREDENTIALS_JSON: '${{ secrets.GCP_CREDENTIALS_JSON }}'
SLACK_TOKEN: '${{ secrets.SLACK_TOKEN }}' #Optional
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} #Optional. For when `update_pr` is `comment`
show_history: 'true'
pr_comment: 'true'
github_token: ${{ secrets.GITHUB_TOKEN }}
```
## 🔧 Environment Setup
- **Firebase Google Credentials**: Export a [service account](https://firebase.google.com/docs/admin/setup#initialize_the_sdk_in_non-google_environments) JSON file from your Firebase Console.
- **Slack Integration**: Optional. Create a Slack app for notifications and obtain its token.
- **Pull request comment**: Optional. Set the `GITHUB_TOKEN` env with `pull_request` and `issues` write permission enabled
- **Pull request comment**: Optional. Set the `github_token` input with `pull_request` and `issues` write permission enabled


## 📜 License
This project is licensed under the MIT License. See the [LICENSE](https://opensource.org/license/mit) file for more details.
This project is licensed under the [BSD-3 License](LICENSE). See the LICENSE file for details.

## 🤝 Contributing
Contributions are welcome! Open issues or submit [pull requests](https://github.com/cybersokari/allure-report-deployer) to improve this action.
36 changes: 19 additions & 17 deletions action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,46 +8,48 @@ branding:

runs:
using: "docker"
image: "docker://sokari/allure-deployer:1.3.0"
args:
- storage_bucket=${{ inputs.storage_bucket }}
- report_name=${{ inputs.report_name }}
- slack_channel=${{ inputs.slack_channel }}
- allure_results_path=${{ inputs.allure_results_path }}
- retries=${{ inputs.retries }}
- show_history=${{ inputs.show_history }}
- prefix=${{ inputs.prefix}}
- update_pr=${{inputs.update_pr}}
- output=${{inputs.output}}
image: "Dockerfile"

inputs:
storage_bucket:
description: "Google Cloud Storage bucket name"
google_credentials_json:
description: "Firebase (Google Cloud) credentials JSON"
required: true
storage_bucket:
description: "A Google Cloud Storage bucket for managing Allure History and Retries"
required: false
report_name:
description: "Name/Title of your report"
default: "Allure Report"
slack_channel:
description: "Slack channel ID for notifications (optional)"
required: false
slack_token:
description: "Slack Token"
required: false
allure_results_path:
description: "Path to the directory containing Allure results"
required: true
retries:
description: "Number of previous test runs to show as retries in new test report (Default 0)"
default: 0
default: '0'
show_history:
description: "Show history in the test report (true/false)"
default: "true"
prefix:
description: "The storage bucket path to back up Allure results and history files"
required: false
update_pr:
description: "Add report info (url and status) as pull request comment or actions summary"
default: "summary"
pr_comment:
description: "Post test report information as pull request comment. Requires `github_token` to be set with permission "
default: "false"
output:
description: "A directory to generate Allure report into. Setting this value disables report hosting and Slack notification"
required: false
github_token:
description: "Set generated GITHUB_TOKEN for adding report info to pr as comment and deploying report to GitHub pages"
required: false
github_pages_branch:
description: "Set target branch for Deploying test report to GitHub Pages"
required: false

outputs:
report_url:
Expand Down
9 changes: 9 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
version: "3.8"
services:
test-action:
build:
context: .
dockerfile: Dockerfile
env_file: .env
volumes:
- /Users/sokari/IdeaProjects/allure-deployer/assets/allure-results:/github/workspace/allure-results
50 changes: 50 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/bin/sh

# Exit immediately if a command exits with a non-zero status
set -e

# Validate required inputs
if [ -z "$INPUT_GOOGLE_CREDENTIALS_JSON" ]; then
echo "error: google_credentials_json is not provided" >&2
exit 1
fi

if [ -z "$INPUT_ALLURE_RESULTS_PATH" ]; then
echo "Error: allure_results_path is not provided" >&2
exit 1
fi

# Create directory for the JSON file
DIR="/credentials"
mkdir -p "$DIR"
JSON_FILE="$DIR/key.json"
# Write the $GOOGLE_CREDENTIALS_JSON content to the JSON file
echo "$INPUT_GOOGLE_CREDENTIALS_JSON" > "$JSON_FILE" # No cleanup needed, in non mounted Docker path
# Export as GOOGLE_APPLICATION_CREDENTIALS for Firebase CLI auto auth
export GOOGLE_APPLICATION_CREDENTIALS="$JSON_FILE"

# Construct the command with all optional variables
if [ -n "$INPUT_OUTPUT" ]; then
deploy_command="allure-deployer generate \"$INPUT_ALLURE_RESULTS_PATH\""
[ -n "$INPUT_REPORT_NAME" ] && deploy_command="$deploy_command $INPUT_REPORT_NAME"
[ -n "$GOOGLE_APPLICATION_CREDENTIALS" ] && deploy_command="$deploy_command --gcp-json $GOOGLE_APPLICATION_CREDENTIALS"
[ -n "$INPUT_STORAGE_BUCKET" ] && deploy_command="$deploy_command --bucket $INPUT_STORAGE_BUCKET"
[ "$INPUT_RETRIES" ] && deploy_command="$deploy_command --retries $INPUT_RETRIES"
[ "$INPUT_SHOW_HISTORY" = "true" ] && deploy_command="$deploy_command --show-history"
[ -n "$INPUT_PREFIX" ] && deploy_command="$deploy_command --prefix $INPUT_PREFIX"
deploy_command="$deploy_command --output /github/workspace/$INPUT_OUTPUT"
else
deploy_command="allure-deployer deploy \"$INPUT_ALLURE_RESULTS_PATH\""
[ -n "$INPUT_REPORT_NAME" ] && deploy_command="$deploy_command $INPUT_REPORT_NAME"
[ -n "$GOOGLE_APPLICATION_CREDENTIALS" ] && deploy_command="$deploy_command --gcp-json $GOOGLE_APPLICATION_CREDENTIALS"
[ -n "$INPUT_STORAGE_BUCKET" ] && deploy_command="$deploy_command --bucket $INPUT_STORAGE_BUCKET"
[ "$INPUT_RETRIES" ] && deploy_command="$deploy_command --retries $INPUT_RETRIES"
[ "$INPUT_SHOW_HISTORY" = "true" ] && deploy_command="$deploy_command --show-history"
[ -n "$INPUT_SLACK_CHANNEL" ] && deploy_command="$deploy_command --slack-channel $INPUT_SLACK_CHANNEL"
[ -n "$INPUT_SLACK_TOKEN" ] && deploy_command="$deploy_command --slack-token $INPUT_SLACK_TOKEN"
[ -n "$INPUT_PREFIX" ] && deploy_command="$deploy_command --prefix $INPUT_PREFIX"
fi

# Execute the constructed command
eval "$deploy_command"
#tail -f /dev/null

0 comments on commit d167b07

Please sign in to comment.