Skip to content

ci: update actions, gcp prep, dependabot #1

ci: update actions, gcp prep, dependabot

ci: update actions, gcp prep, dependabot #1

Workflow file for this run

name: Build and Test
on:
push:
branches:
- main
- dev
pull_request:
branches:
- main
- dev
concurrency:
group: "${{ github.head_ref || github.ref }}"
cancel-in-progress: true
jobs:
test:
name: Setup and Test
runs-on: ubuntu-latest
steps:
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.9"
# cache: pip
# cache-dependency-path: setup.py
- name: Checkout code
uses: actions/checkout@v4
with:
show-progress: false
- name: Install module
run: pip install .[tests]
- name: Test with pytest
run: pytest
deploy-dev:
name: Deploy to GCF
needs: test
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/dev'
environment:
name: dev
permissions:
id-token: write
contents: read
steps:
- name: ⬇️ Set up code
uses: actions/checkout@v4
with:
show-progress: false
- name: 🗝️ Authenticate to Google Cloud
id: auth
uses: google-github-actions/auth@v1
with:
create_credentials_file: true
token_format: access_token
workload_identity_provider: ${{ secrets.IDENTITY_PROVIDER }}
service_account: ${{ secrets.SERVICE_ACCOUNT_EMAIL }}
- name: 🚀 Deploy to Cloud Function
id: deploy
uses: google-github-actions/deploy-cloud-functions@v1
with:
name: nfhl-skid
runtime: python39
entry_point: main
source_dir: src/nfhl
service_account_email: cloud-function-sa@${{ secrets.PROJECT_ID }}.iam.gserviceaccount.com
event_trigger_type: providers/cloud.pubsub/eventTypes/topic.publish
event_trigger_resource: projects/${{ secrets.PROJECT_ID }}/topics/saturday-night-topic
deploy_timeout: 600
memory_mb: 512
timeout: 240
env_vars: STORAGE_BUCKET=${{secrets.STORAGE_BUCKET}}
secret_volumes: |
/secrets/app/secrets.json=${{secrets.PROJECT_ID}}/app_secrets
- name: 📥 Create PubSub topic
run: |
if [ ! "$(gcloud pubsub topics list | grep saturday-night-topic)" ]; then
gcloud pubsub topics create saturday-night-topic --quiet
fi
- name: 🕰️ Create Cloud Scheduler
run: |
if [ ! "$(gcloud scheduler jobs list --location=us-central1 | grep monday-morning)" ]; then
gcloud scheduler jobs create pubsub monday-morning \
--description="Trigger the nfhl-skid bot once a week on monday morning" \
--schedule="0 23 * * 6" \
--time-zone=America/Denver \
--location=us-central1 \
--topic=saturday-night-topic \
--message-body='{"run": "now"}' \
--quiet
else
gcloud scheduler jobs update pubsub monday-morning \
--description="Trigger the nfhl-skid bot once a week on monday morning" \
--schedule="0 23 * * 6" \
--time-zone=America/Denver \
--location=us-central1 \
--topic=saturday-night-topic \
--message-body='{"run": "now"}' \
--quiet
fi
deploy-prod:
name: Deploy to GCF
needs: test
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
environment:
name: prod
permissions:
id-token: write
contents: read
steps:
- name: ⬇️ Set up code
uses: actions/checkout@v4
with:
show-progress: false
- name: 🗝️ Authenticate to Google Cloud
id: auth
uses: google-github-actions/auth@v1
with:
create_credentials_file: true
token_format: access_token
workload_identity_provider: ${{ secrets.IDENTITY_PROVIDER }}
service_account: ${{ secrets.SERVICE_ACCOUNT_EMAIL }}
- name: 🚀 Deploy to Cloud Function
id: deploy
uses: google-github-actions/deploy-cloud-functions@v1
with:
name: nfhl-skid
runtime: python39
entry_point: main
source_dir: src/projectname
service_account_email: cloud-function-sa@${{ secrets.PROJECT_ID }}.iam.gserviceaccount.com
event_trigger_type: providers/cloud.pubsub/eventTypes/topic.publish
event_trigger_resource: projects/${{ secrets.PROJECT_ID }}/topics/saturday-night-topic
deploy_timeout: 600
memory_mb: 512
timeout: 240
env_vars: STORAGE_BUCKET=${{secrets.STORAGE_BUCKET}}
secret_volumes: |
/secrets/app/secrets.json=${{secrets.PROJECT_ID}}/app_secrets
- name: 📥 Create PubSub topic
run: |
if [ ! "$(gcloud pubsub topics list | grep saturday-night-topic)" ]; then
gcloud pubsub topics create saturday-night-topic --quiet
fi
- name: 🕰️ Create Cloud Scheduler
run: |
if [ ! "$(gcloud scheduler jobs list --location=us-central1 | grep monday-morning)" ]; then
gcloud scheduler jobs create pubsub monday-morning \
--description="Trigger the nfhl-skid bot once a week on monday morning" \
--schedule="0 23 * * 6" \
--time-zone=America/Denver \
--location=us-central1 \
--topic=saturday-night-topic \
--message-body='{"run": "now"}' \
--quiet
else
gcloud scheduler jobs update pubsub monday-morning \
--description="Trigger the nfhl-skid bot once a week on monday morning" \
--schedule="0 23 * * 6" \
--time-zone=America/Denver \
--location=us-central1 \
--topic=saturday-night-topic \
--message-body='{"run": "now"}' \
--quiet
fi