Skip to content

TestRail Backup

TestRail Backup #34

Workflow file for this run

name: TestRail Backup
on:
workflow_dispatch:
env:
BUCKET: backups-testrail-test-suites
DEFAULT_DIR: ./backup-tools
PROJECT_IDS: 59 14 27 13 48
# Fenix Browser: 59
# Firefox for iOS: 14
# Focus for iOS: 27
# Firefox for Android: 13
# Focus for Android:48
STORAGE_URL_PREFIX: https://storage.googleapis.com
jobs:
test:
name: Backup test suites
runs-on: ubuntu-24.04
defaults:
run:
working-directory: ${{ env.DEFAULT_DIR }}
env:
TESTRAIL_HOST: ${{ secrets.TESTRAIL_HOST }}
TESTRAIL_USERNAME: ${{ secrets.TESTRAIL_USERNAME }}
TESTRAIL_PASSWORD: ${{ secrets.TESTRAIL_PASSWORD }}
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL_TEST_ALERTS_SANDBOX }}
steps:
- name: Checkout code
uses: actions/[email protected]
- name: Set up Python
uses: actions/[email protected]
with:
python-version: 3.11
- name: Install dependencies
run: |
pip install -r requirements.txt
- name: Fetch test cases
run: |
python backup_testrail.py ${{ env.PROJECT_IDS }}
- name: Create file listing
run: |
touch Listing.md
echo "# Projects & Test Suites" >> Listing.md
echo "" >> Listing.md
echo "| Project | Test Suite | File |" >> Listing.md
echo "|---------|------------|------|" >> Listing.md
ls *.csv > files.txt
awk -F '_' '{print "| " $2 " | " $3 " | `" $0 "` |"}' < files.txt >> Listing.md
- name: Create gzip file containing csv and listing
run: |
today=`date "+%Y-%m-%d"`
subdir=`date "+%Y-%m"`
filename=$today-TestRail-backup
mkdir $filename
mv *.csv $filename
mv Listing.md $filename
tar -cvzf $filename.tgz $filename/*
echo "filename=$filename" >> $GITHUB_ENV
echo "subdir=$subdir" >> $GITHUB_ENV
- name: Establish Google Cloud connection
uses: google-github-actions/auth@v2
with:
credentials_json: ${{ secrets.GCLOUD_AUTH }}
- name: Upload CSV files to GCP bucket
id: upload-file
uses: google-github-actions/upload-cloud-storage@v2
with:
path: ${{ env.DEFAULT_DIR }}/${{ env.filename }}.tgz
destination: ${{ env.BUCKET }}/${{ env.subdir }}
- name: Output URL to Github Actions summary
run: |
echo "[Download CSV files](${{ env.STORAGE_URL_PREFIX }}/${{ env.BUCKET }}/${{ steps.upload-file.outputs.uploaded }})" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "Projects Included in the Backup" >> $GITHUB_STEP_SUMMARY
cd $filename
ls *.csv > files.txt
awk -F '_' '{print "* " $2 }' < files.txt | uniq >> $GITHUB_STEP_SUMMARY
- name: Notify Slack for failures
uses: slackapi/[email protected]
if: ${{ failure() }}
with:
channel-id: ${{ secrets.SLACK_MOBILE_ALERTS_SANDBOX_CHANNEL }}
payload: |
{
"blocks": [
{
"type": "header",
"text": {
"type": "plain_text",
"text": ":sad: TestRail Backup Failed :sad:",
"emoji": true
}
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "<${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|Github Actions Job>"
}
}
]
}
- name: Notify Slack for successful job
uses: slackapi/[email protected]
if: ${{ success() }}
with:
channel-id: ${{ secrets.SLACK_MOBILE_ALERTS_SANDBOX_CHANNEL }}
payload: |
{
"blocks": [
{
"type": "header",
"text": {
"type": "plain_text",
"text": "TestRail Backup Successful :smiley:",
"emoji": true
}
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "<${{ env.STORAGE_URL_PREFIX }}/${{ env.BUCKET }}/${{ steps.upload-file.outputs.uploaded }}|Archive>"
}
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "<${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|Github Actions Job>"
}
}
]
}