Skip to content

Commit

Permalink
feat: Slack bot!
Browse files Browse the repository at this point in the history
  • Loading branch information
cybersokari committed Dec 7, 2024
1 parent 038ed37 commit 39bd821
Show file tree
Hide file tree
Showing 22 changed files with 3,138 additions and 253 deletions.
2 changes: 2 additions & 0 deletions .env.slack.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
SLACK_TOKEN=
SLACK_CONVERSION_ID=
2 changes: 2 additions & 0 deletions .github/workflows/actions-example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ jobs:
-e WEBSITE_EXPIRES=${{ github.event.inputs.website-expires }} \
-e KEEP_RETRIES=${{ github.event.inputs.keep-retries }} \
-e KEEP_HISTORY=${{ github.event.inputs.keep-history }} \
-e SLACK_TOKEN=${{secrets.SLACK_TOKEN}} \
-e SLACK_CHANNEL_ID=${{secrets.SLACK_CHANNEL_ID}} \
-v $GITHUB_STEP_SUMMARY:/github/summary.txt \
-v ${{ github.workspace }}/assets/allure-results:/allure-results \
-v ${{ github.workspace }}/gcp-key.json:/credentials/gcp-key.json \
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ allure-firebase.iml
*/node_modules
worker/allure-*
worker/lib
credentials/gcp-key.json
credentials/gcp-key.json
.env.slack
8 changes: 4 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ RUN npm install -g firebase-tools
RUN mkdir "allure-results" # create staging
# Copy app files and install deps
COPY worker/. /app/
RUN npm install -g typescript
RUN npm install --omit=dev && npm run build
RUN npm uninstall -g typescript
#RUN npm install -g typescript
#RUN npm install --omit=dev && npm run build
#RUN npm uninstall -g typescript
## Remove .ts files
RUN rm -rf app
#RUN rm -rf app

COPY start.sh /
CMD ["/bin/sh", "/start.sh"]
27 changes: 22 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Works in both CI and local environments with minimal setup, utilizing [Firebase

- **Cloud Storage**: Automatically backs up Allure test results and history in a Google Cloud Storage bucket.
- **Preview URLs**: Generates ephemeral Allure report URLs hosted on Firebase for easy sharing with stakeholders.
- **Slack Integration**: _(Coming Soon)_ Notify team members with preview URLs directly in Slack after each test run.
- **Slack Integration**: Notify team members with preview URLs directly in Slack after each test run.
- **Continuous Deployment**: In Watch Mode, the container detects changes, generates reports, and uploads them automatically. Suitable for testing locally.


Expand Down Expand Up @@ -75,13 +75,28 @@ jobs:

```

**URL preview in GitHub Actions job summary**
---

#### View your report details in GitHub Actions job summary

<div style="text-align: left"><img src="assets/example-github-summary.png" alt="URL preview in GitHub Actions summary"></div>

**Test result files in Firebase Storage**
---

#### Receive build success update in Slack

<div style="text-align: left"><img src="assets/slack-bot.png" alt="URL preview in GitHub Actions summary"></div>

---

#### View your test result file on the Firebase Developer console

<div><img src="assets/storage-dashboard.png" alt="Test result files in Firebase Storage"></div>

**Test report example site**
---

#### Test report example site

<div><img src="assets/site.png" alt="Test report example site"></div>

Tips
Expand Down Expand Up @@ -179,6 +194,8 @@ services:
| `KEEP_RETRIES` | Backup files in the `allure-results` directory after report generation | false |
| `WATCH_MODE` | Keep the container running to auto deploy new test reports and results | false |
| `TTL_SECS` | Time to wait (in seconds) after last file is detected before generating and uploading the report. Only works when `WATCH_MODE=true` | 45 |
| `SLACK_TOKEN` | Your Slack Bot token | None |
| `SLACK_CHANNEL_ID` | The ID of the channel or conversation you want to receive your status | None |

**Note**: Either `STORAGE_BUCKET` or `WEBSITE_ID` must be provided. Both can be configured if you want to enable all functionalities.

Expand All @@ -193,7 +210,7 @@ services:
| **Cloud Storage backup** | ✅ Automatically backs up test result files to Google Cloud Storage. | ❌ No backup functionality; relies on GitHub repositories for report storage. |
| **Direct deployment without Git commits** | ✅ Deploys directly to Firebase Hosting without committing generated reports to Git. | ❌ Requires committing generated reports to GitHub Pages. |
| **Further analysis capabilities** | ✅ Allows access to all saved test result files for additional analysis beyond the Allure-generated report. | ❌ No such functionality provided. |
| **Slack notifications** | 🚧 Planned (Coming Soon). | ❌ Not supported. |
| **Slack notifications** | ✅ Receive your test report URL in Slack | ❌ Not supported. |



Expand Down
77 changes: 77 additions & 0 deletions assets/slack-block-template.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
{
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*Your Allure report is ready* :female-teacher:"
}
},
{
"type": "context",
"elements": [
{
"type": "mrkdwn",
"text": ":file_folder: *Files uploaded:* 54"
}
]
},
{
"type": "context",
"elements": [
{
"type": "mrkdwn",
"text": ":mag: *Files processed:* 49"
}
]
},
{
"type": "context",
"elements": [
{
"type": "mrkdwn",
"text": ":stopwatch: *Duration:* 11.206 seconds"
}
]
},
{
"type": "actions",
"elements": [
{
"type": "button",
"text": {
"type": "plain_text",
"text": "View report",
"emoji": true
},
"value": "click_me_123"
},
{
"type": "button",
"text": {
"type": "plain_text",
"text": "View files in storage",
"emoji": true
},
"value": "click_me_123",
"url": "https://google.com"
}
]
},
{
"type": "actions",
"elements": [
{
"type": "button",
"text": {
"type": "plain_text",
"text": "Star us on GitHub :smile:",
"emoji": true
},
"value": "click_me_123",
"action_id": "actionId-0"
}
]
}
]
}
Binary file added assets/slack-bot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 4 additions & 5 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ services:
image: goatlab/firebase-emulator:1.2-arm64
container_name: emulator
ports:
- "9199:9199" # Storage
- "4001:3000" # UI
- "4000:4000" # UI
- "9199:9199"
- "4000:4000"
command: ["firebase", "emulators:start", "--only", "storage,logging", "--project", "fir-demo-project", '--config', "./startfirebase.json"]
restart: unless-stopped
healthcheck:
Expand All @@ -20,8 +19,8 @@ services:
dockerfile: Dockerfile
context: .
container_name: allure-deployer
env_file: .env.slack
environment:
DEBUG: true # Dev mode
FIREBASE_STORAGE_EMULATOR_HOST: 127.0.0.1:9199 # Dev mode
GOOGLE_APPLICATION_CREDENTIALS: ${PWD}/service-account.json
STORAGE_BUCKET: "fir-demo-project.appspot.com"
Expand All @@ -32,7 +31,7 @@ services:
# WATCH_MODE: true
TTL_SECS: 4
volumes:
- ./worker:/app #devs only. This overrides the /app dir
- ./worker:/app #Devs only. This overrides the /app dir
- ${PWD}/gcp-key.json:${PWD}/service-account.json:ro
- /Users/sokari/IdeaProjects/appium/reports/ios/allure-results:/allure-results
cpus: 1
Expand Down
2 changes: 1 addition & 1 deletion start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ fi
GITHUB_SUMMARY_FILE="/github/summary.txt"
if [ ! -f "$GITHUB_SUMMARY_FILE" ]; then
export GITHUB_SUMMARY_FILE
echo "Git summary file directory mounted"
echo "Running on GitHub. Summary will be available in a bit"
fi

if [ -n "$TTL_SECS" ]; then
Expand Down
18 changes: 18 additions & 0 deletions test.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
FROM node:22-alpine@sha256:adeb6d34aff46b81fb1dcf746961b6363180c53a91741c3c5c5db926c8df576c
#WORK_DIR env is used in code to manage files
ENV WORK_DIR=/app
WORKDIR $WORK_DIR
USER root
# JRE for Allure commandline
RUN apk add openjdk17-jre
# Firebase Hosting
RUN npm install -g firebase-tools
# Mount dir /allure-results
# Staging dir /app/allure-results
RUN mkdir "allure-results" # create staging
# Copy app files and install deps
COPY worker/. /app/
RUN npm install -g typescript
RUN npm install

CMD ["npm", "run", "test"]
2 changes: 0 additions & 2 deletions worker/app/cloud-storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,6 @@ export class CloudStorage {
}

public async uploadResults() {
// try to delete any history file in STAGING_PATH/history
// await fs.rm(`${STAGING_PATH}/history`, {recursive: true,force: true});
const files = getAllFilesStream(MOUNTED_PATH)
await this.uploadFiles(files)
}
Expand Down
Loading

0 comments on commit 39bd821

Please sign in to comment.