CI Workflow for API Integration Testing #47
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: CI Workflow for API Integration Testing | |
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
branches: | |
- main | |
workflow_dispatch: | |
jobs: | |
# Add timestamp | |
print_timestamp: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Generate timestamp | |
run: | | |
echo "TIMESTAMP=$(TZ='America/Los_Angeles' date +'%Y-%m-%d %H:%M:%S')" >> $GITHUB_ENV | |
- name: Print timestamp | |
run: | | |
echo "Execution time (Pacific Time Zone) $TIMESTAMP" | |
test-and-publish: | |
needs: print_timestamp | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout Code | |
uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2 | |
- name: Use Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: 20 | |
- name: Install pnpm | |
run: npm install -g pnpm | |
- name: Install Dependencies | |
run: pnpm install | |
- name: Lint | |
run: pnpm eslint . | |
# Ensure you have a lint script in your package.json | |
- name: Run Tests On Sepolia | |
continue-on-error: true | |
run: | | |
echo "Load environment variables" | |
rm .env && touch .env | |
echo API_BASE_URL=${{ secrets.API_BASE_URL }} > .env | |
echo API_KEY=${{ secrets.API_KEY }} >> .env | |
test_env=sepolia npx playwright test | |
- name: Run Tests On Story | |
continue-on-error: true | |
run: | | |
echo "Load environment variables" | |
rm .env && touch .env | |
echo API_BASE_URL=${{ secrets.API_BASE_URL }} > .env | |
echo API_KEY=${{ secrets.API_KEY }} >> .env | |
test_env=story npx playwright test | |
- name: Push Slack Notification | |
uses: slackapi/[email protected] | |
with: | |
channel-id: ${{ secrets.SLACK_CHANNEL_ID_GITHUB_NOTIFICATION }} | |
payload: | | |
{ | |
"text": "${{ github.repository }}: API Integration Tests have been completed. Check the results at github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}", | |
"blocks": [ | |
{ "type": "divider" }, | |
{ | |
"type": "image", | |
"title": { | |
"type": "plain_text", | |
"text": "Playwright Test Results" | |
}, | |
"image_url": "http://www.quickmeme.com/img/b9/b9848df257b95cd39585368475a4b4e4a3a8c774f7390226daecb79b912087ad.jpg", | |
"alt_text": "Playwright Test Results" | |
}, | |
{ | |
"type": "section", | |
"text": { | |
"type": "mrkdwn", | |
"text":"${{ github.repository }}: API Integration Tests have been completed. \nCheck the results at https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}" | |
} | |
} | |
] | |
} | |
env: | |
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }} | |
- name: Upload Test Results | |
uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 | |
# if: failure() && github.event_name == 'push' && github.ref == 'refs/heads/main' | |
with: | |
name: sepolia-test-reports | |
path: | | |
./playwright-report-sepolia/index.html | |
- name: Upload Test Results | |
uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 | |
# if: failure() && github.event_name == 'push' && github.ref == 'refs/heads/main' | |
with: | |
name: story-test-reports | |
path: | | |
./playwright-report-story/index.html |