shut er' down. #21
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
# Workflow for deploying static content to GitHub Pages, running a racket orchestration suite, and a python application. | |
name: Deploy static content to Pages | |
on: | |
# Runs on pushes targeting the default branch | |
push: | |
branches: ["production"] | |
# Allows you to run this workflow manually from the Actions tab | |
workflow_dispatch: | |
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages | |
permissions: | |
contents: read | |
pages: write | |
id-token: write | |
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued. | |
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete. | |
concurrency: | |
group: "pages-deploy" | |
cancel-in-progress: false | |
jobs: | |
deploy: | |
environment: | |
name: github-pages | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4.2.2 | |
- name: Setup Pages | |
uses: actions/configure-pages@v5 | |
- name: Upload artifact | |
uses: actions/upload-pages-artifact@v3.0.1 | |
with: | |
path: '.' | |
- name: Deploy to GitHub Pages | |
id: deployment | |
uses: actions/deploy-pages@v4 | |
outputs: | |
page_url: ${{ steps.deployment.outputs.page_url }} | |
build-and-test-python: | |
needs: deploy | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4.2.2 | |
- name: Set up Python 3.13 | |
uses: actions/setup-python@v5.3.0 | |
with: | |
python-version: "3.13" | |
- name: Navigate to directory with main.py and print current directory | |
run: | | |
cd ${{ github.workspace }} | |
pwd | |
ls -la | |
- name: Create logs directory | |
run: mkdir -p logs | |
- name: Set permissions for logs directory | |
run: chmod 755 logs | |
- name: Create setup log file | |
run: touch logs/setup.log | |
- name: Create run log file | |
run: touch logs/python-app.log | |
- name: Create app log file | |
run: touch logs/app.log | |
- name: Create and activate Python virtual environment | |
run: | | |
python -m venv venv | |
source venv/bin/activate | |
echo $PATH | tee -a logs/setup.log 2>&1 | |
echo $VIRTUAL_ENV | tee -a logs/setup.log 2>&1 | |
echo $PYTHONPATH | tee -a logs/setup.log 2>&1 | |
- name: Install dependencies and set up environment | |
run: | | |
sudo apt-get update | |
sudo apt-get upgrade -y >> logs/setup.log 2>&1 | |
python -m pip install --upgrade pip >> logs/setup.log 2>&1 | |
sudo apt install curl -y | |
echo "::set-output name=result::success" >> logs/setup.log 2>&1 | |
- name: Run main python app | |
run: | | |
source venv/bin/activate | |
python3 main.py -- python3 ./src/__init__.py 2>&1 | tee -a logs/app.log logs/python-app.log | |
- name: Archive test output as artifact | |
if: always() | |
uses: actions/upload-artifact@v4.6.0 | |
with: | |
name: python-app | |
path: logs/python-app.log | |
validate-repository-state: | |
needs: [deploy, build-and-test-python] | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4.2.2 | |
- name: Set up Racket and jq | |
run: | | |
sudo apt-get update | |
sudo apt-get install -y racket jq | |
- name: Prepare Racket input data | |
run: | | |
mkdir -p logs | |
cat <<EOF > inputs.json | |
{ | |
"repository": [ | |
{"id": 1, "branch": "production", "permissions": ["x"], "state": "valid"} | |
] | |
} | |
EOF | |
- name: Verify `inputs.json` exists | |
run: | | |
if [ ! -f inputs.json ]; then | |
echo "Error: inputs.json does not exist!" >&2 | |
exit 1 | |
fi | |
- name: Validate `inputs.json` syntax and structure | |
run: | | |
jq . inputs.json > /dev/null || { echo "Error: inputs.json is not valid JSON!" >&2; exit 1; } | |
if ! jq -e '.repository and (.repository | length > 0)' inputs.json > /dev/null; then | |
echo "Error: inputs.json does not contain a valid 'repository' array!" >&2 | |
exit 1 | |
fi | |
- name: Format `inputs.json` | |
run: | | |
jq . inputs.json > inputs.tmp && mv inputs.tmp inputs.json | |
- name: Print `inputs.json` content for debugging | |
run: cat inputs.json | |
- name: Run Racket script to validate repository state | |
run: | | |
racket -t sys.rkt inputs.json > logs/racket-validation.log 2>&1 || { | |
echo "Racket validation failed. Check logs/racket-validation.log for details." >&2; | |
cat logs/racket-validation.log; | |
exit 1; | |
} | |
- name: Archive Racket validation output as artifact | |
if: always() | |
uses: actions/upload-artifact@v4.6.0 | |
with: | |
name: racket-validation | |
path: logs/racket-validation.log | |
set-environment-url: | |
needs: [deploy, build-and-test-python, validate-repository-state] | |
runs-on: ubuntu-latest | |
environment: | |
name: github-pages | |
url: ${{ needs.deploy.outputs.page_url }} | |
steps: | |
- name: No-op step (just to finalize the environment URL) | |
run: echo "Environment URL set to ${{ needs.deploy.outputs.page_url }}" |