Skip to content

ci: test matrix summary #11

ci: test matrix summary

ci: test matrix summary #11

Workflow file for this run

name: Deploy
on:
pull_request:
branches:
- main
jobs:
deploy:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
entry: [sm, saas] # Add more entries as needed
steps:
- name: Checkout code
uses: actions/checkout@v2
# Your deployment step here
- name: Deploy to ${{ matrix.entry }}
run: |
# Your deployment script goes here
# Simulate deployment process and create a success/failure status
echo "Deploying to ${{ matrix.entry }}"
if [ "${{ matrix.entry }}" = "sm" ]; then
exit 0
else
exit 1
fi
- name: Save deployment status
if: always()
run: |
mkdir -p deployment_status
echo "${{ matrix.entry }}=${{ job.status }}" > deployment_status/status_${{ matrix.entry }}.txt
- name: Upload deployment status artifact
if: always()
uses: actions/upload-artifact@v3
with:
name: deployment-status-${{ github.run_id }}-${{ github.run_attempt }}-${{ matrix.entry }}
path: deployment_status/status_${{ matrix.entry }}.txt
summarize:
if: always()
needs: deploy
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Download deployment status artifacts
run: |
mkdir -p deployment_status
for artifact in $(curl -s \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
"https://api.github.com/repos/${{ github.repository }}/actions/runs/${{ github.run_id }}/artifacts" \
| jq -r '.artifacts[].name'); do
if [[ "${artifact}" == deployment-status-${{ github.run_id }}-${{ github.run_attempt }}-* ]]; then
echo "names match $artifact"
gh run download ${{ github.run_id }} -n "${artifact}" --dir deployment_status
else
echo "names don't match. looking for: deployment-status-${{ github.run_id }}-${{ github.run_attempt }}-* but got ${artifact}"
fi
done
- name: Summarize deployment statuses
run: |
summary="Deployment status summary:\n"
for file in deployment_status/**/*.txt; do
entry=$(basename "$file" .txt | cut -d'_' -f2)
status=$(cat "$file")
summary+="$entry: $status\n"
done
echo "$summary" > summary.txt
echo "$summary"
- name: Post summary as a comment
if: github.event_name == 'pull_request'
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const summary = fs.readFileSync('summary.txt', 'utf8');
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: summary,
});