-
Notifications
You must be signed in to change notification settings - Fork 2
127 lines (108 loc) · 4.11 KB
/
testrail-backup.yml
File metadata and controls
127 lines (108 loc) · 4.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
name: TestRail Backup
on:
workflow_dispatch:
schedule:
- cron: "0 15 * * *" # Run every day at 3pm
env:
BUCKET: backups-testrail-test-suites
DEFAULT_DIR: ./backup-tools
PROJECT_IDS: 59 14 27 48
# Fenix Browser: 59
# Firefox for iOS: 14
# Focus for iOS: 27
# Focus for Android: 48
STORAGE_URL_PREFIX: https://storage.googleapis.com
jobs:
test:
name: Backup test suites
runs-on: ubuntu-24.04
permissions:
contents: write
defaults:
run:
working-directory: ${{ env.DEFAULT_DIR }}
env:
TESTRAIL_HOST: ${{ secrets.TESTRAIL_HOST }}
TESTRAIL_USERNAME: ${{ secrets.TESTRAIL_USERNAME }}
TESTRAIL_PASSWORD: ${{ secrets.TESTRAIL_PASSWORD }}
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: 3.11
- name: Install dependencies
run: |
pip install -r requirements.txt
sudo apt-get install gnupg
- 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=`openssl rand -hex 20`
filename=$today-TestRail-backup
mkdir $filename
mv *.csv $filename
mv Listing.md $filename
cp README.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@v3
with:
credentials_json: ${{ secrets.GCLOUD_AUTH }}
- name: Upload CSV files to GCP bucket
id: upload-file
uses: google-github-actions/upload-cloud-storage@v3
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: Output test case counts to Github Actions summary
run: bash output-test-counts.sh test-counts.json slack-counts.json
- name: Commit updated test counts
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add test-counts.json
git diff --staged --quiet || git commit -m "Update test case counts [skip ci]"
git push
- name: Notify Slack - Test case counts
uses: slackapi/slack-github-action@v3.0.2
with:
webhook: ${{ secrets.SLACK_WEBHOOK_URL_TEST_ALERTS_SANDBOX }}
webhook-type: incoming-webhook
payload-file-path: ${{ env.DEFAULT_DIR }}/slack-counts.json
- name: Notify Slack (Fail)
uses: slackapi/slack-github-action@v3.0.2
if: ${{ failure() }}
with:
webhook: ${{ secrets.SLACK_WEBHOOK_MOBILE_ALERTS_TOOLING }}
webhook-type: incoming-webhook
payload-file-path: ${{ env.DEFAULT_DIR }}/slack-fail.json
payload-templated: true
env:
server_url: ${{ github.server_url }}
repository: ${{ github.repository }}
run_id: ${{ github.run_id }}
branch: ${{ github.ref_name }}