Overview
This documentation provides a detailed explanation of the setup for a cron job scheduled test in a GitHub Actions workflow. The purpose of this setup is to automate the execution of test scripts against a Postman collection every 15 minutes, ensuring continuous testing and monitoring of the boilerplate repository's API endpoints.
GitHub Actions Workflow Configuration
name: Scheduled Test
on:
schedule:
- cron: '*/15 * * * *'
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Run test script
env:
POSTMAN_API_KEY: ${{ secrets.POSTMAN_API_KEY }}
API_URL: ${{ secrets.API_URL }}
run: |
cd qa
chmod +x test.sh
./test.sh
Key Components:
-
Schedule Trigger (
on: schedule
): The workflow is triggered every 15 minutes as specified by the cron expression'*/15 * * * *'
. -
Environment Variables:
-
POSTMAN_API_KEY
: The API key for accessing the Postman collection (stored securely in GitHub Secrets). -
API_URL
: The base URL of the API under test.
-
-
Steps:
-
Checkout Repository: Uses the
actions/checkout@v3
action to check out the repository code. -
Run Test Script: Executes the
test.sh
script located in theqa
directory, which handles the installation of necessary dependencies and triggers the test execution.
-
Checkout Repository: Uses the
Test Script (test.sh
)
npm install newman
npm install axios
npm install big-json
node ./index.js
Explanation:
-
Dependency Installation:
-
newman
: A command-line tool to run Postman collections. -
axios
: A promise-based HTTP client for making API requests. -
big-json
: A module to handle large JSON files.
-
-
Running
index.js
: Executes the main script that handles the Postman collection run, compression of results, and subsequent API requests.
Main Script (index.js
) (Not included in this documentation)
The index.js
script orchestrates the entire process, from executing the tests with Newman to compressing the results and sending them to the API.
Conclusion
This setup provides a robust mechanism for automated testing of the boilerplate repository. The workflow ensures that API endpoints are tested every 15 minutes, with detailed logs and results management, enhancing the overall quality and reliability of the project.
Top comments (0)