-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP: Divide github actions into multiple steps #26
Draft
jacobdadams
wants to merge
4
commits into
main
Choose a base branch
from
dev
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
d9fe3e1
ci: refactor github workflow, add requirements.txt
jacobdadams 81c87d8
docs: parameterizing your function with many schedules
jacobdadams 5a14ae5
ci: code already checked out by calling action
jacobdadams 8b0bc28
Apply suggestions from code review
jacobdadams File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
name: Deploy to GCP | ||
description: Deploy to GCP | ||
inputs: | ||
project_id: | ||
description: "The GCP project ID" | ||
required: true | ||
identity_provider: | ||
description: "The identity provider for the workload identity" | ||
required: true | ||
service_account_email: | ||
description: "The service account email" | ||
required: true | ||
storage_bucket: | ||
description: "The GCP storage bucket" | ||
required: true | ||
|
||
runs: | ||
using: composite | ||
steps: | ||
- name: Set globals | ||
id: globals | ||
shell: bash | ||
run: | | ||
echo "MAIN_SCHEDULE_NAME=skidname_main" >> "${GITHUB_OUTPUT}" | ||
echo "MAIN_SCHEDULE_CRON=0 22 * * 6" >> "${GITHUB_OUTPUT}" | ||
echo "MAIN_SCHEDULE_DESCRIPTION=Trigger the skidname-skid bot every saturday evening at 10pm" >> "${GITHUB_OUTPUT}" | ||
echo "VALIDATOR_SCHEDULE_NAME=validator" >> "${GITHUB_OUTPUT}" | ||
echo "VALIDATOR_SCHEDULE_DESCRIPTION=Trigger the skidname validation bot every 1st of April, May, and June at 8am" >> "${GITHUB_OUTPUT}" | ||
echo "VALIDATOR_SCHEDULE_CRON=0 8 1 4-6 *" >> "${GITHUB_OUTPUT}" | ||
echo "TOPIC_NAME=skidname-topic" >> "${GITHUB_OUTPUT}" | ||
|
||
- name: 🗝️ Authenticate to Google Cloud | ||
id: auth | ||
uses: google-github-actions/auth@v2 | ||
with: | ||
create_credentials_file: true | ||
token_format: access_token | ||
workload_identity_provider: ${{ inputs.identity_provider }} | ||
service_account: ${{ inputs.service_account_email }} | ||
|
||
- name: 📥 Create Main PubSub topic | ||
shell: bash | ||
run: | | ||
if [ ! "$(gcloud pubsub topics list | grep ${{ steps.globals.outputs.TOPIC_NAME }})" ]; then | ||
gcloud pubsub topics create ${{ steps.globals.outputs.TOPIC_NAME }} --quiet | ||
fi | ||
|
||
- name: 🚀 Deploy Cloud Function | ||
id: deploy | ||
uses: google-github-actions/deploy-cloud-functions@v3 | ||
with: | ||
name: skidname-skid | ||
runtime: python311 | ||
entry_point: subscribe | ||
source_dir: src/skidname | ||
service_account: cloud-function-sa@${{ inputs.project_id }}.iam.gserviceaccount.com | ||
event_trigger_type: google.cloud.pubsub.topic.v1.messagePublished | ||
event_trigger_pubsub_topic: projects/${{ inputs.project_id }}/topics/${{ steps.globals.outputs.TOPIC_NAME }} | ||
memory: 1024M | ||
service_timeout: 9m | ||
environment_variables: STORAGE_BUCKET=${{ inputs.storage_bucket }} | ||
secrets: | | ||
/secrets/app/secrets.json=${{ inputs.project_id }}/skid-secrets | ||
max_instance_count: 1 | ||
event_trigger_retry: false | ||
|
||
- name: 🕰️ Create Main Cloud Scheduler | ||
shell: bash | ||
run: | | ||
if [ ! "$(gcloud scheduler jobs list --location=us-central1 | grep ${{ steps.globals.outputs.MAIN_SCHEDULE_NAME }})" ]; then | ||
gcloud scheduler jobs create pubsub "${{ steps.globals.outputs.MAIN_SCHEDULE_NAME }}" \ | ||
--description="${{ steps.globals.outputs.MAIN_SCHEDULE_DESCRIPTION }}" \ | ||
--schedule="${{ steps.globals.outputs.MAIN_SCHEDULE_CRON }}" \ | ||
--time-zone=America/Denver \ | ||
--location=us-central1 \ | ||
--topic="${{ steps.globals.outputs.TOPIC_NAME }}" \ | ||
--message-body='run the skid' \ | ||
--quiet | ||
else | ||
gcloud scheduler jobs update pubsub "${{ steps.globals.outputs.MAIN_SCHEDULE_NAME }}" \ | ||
--description="${{ steps.globals.outputs.MAIN_SCHEDULE_DESCRIPTION }}" \ | ||
--schedule="${{ steps.globals.outputs.MAIN_SCHEDULE_CRON }}" \ | ||
--time-zone=America/Denver \ | ||
--location=us-central1 \ | ||
--topic="${{ steps.globals.outputs.TOPIC_NAME }}" \ | ||
--message-body='run the skid' \ | ||
--quiet | ||
fi | ||
|
||
- name: 🕰️ Create Validator Cloud Scheduler | ||
shell: bash | ||
run: | | ||
if [ ! "$(gcloud scheduler jobs list --location=us-central1 | grep ${{ steps.globals.outputs.VALIDATOR_SCHEDULE_NAME }})" ]; then | ||
gcloud scheduler jobs create pubsub "${{ steps.globals.outputs.VALIDATOR_SCHEDULE_NAME }}" \ | ||
--description="${{ steps.globals.outputs.VALIDATOR_SCHEDULE_DESCRIPTION }}" \ | ||
--schedule="${{ steps.globals.outputs.VALIDATOR_SCHEDULE_CRON }}" \ | ||
--time-zone=America/Denver \ | ||
--location=us-central1 \ | ||
--topic="${{ steps.globals.outputs.TOPIC_NAME }}" \ | ||
--message-body='validate' \ | ||
--quiet | ||
else | ||
gcloud scheduler jobs update pubsub "${{ steps.globals.outputs.VALIDATOR_SCHEDULE_NAME }}" \ | ||
--description="${{ steps.globals.outputs.VALIDATOR_SCHEDULE_DESCRIPTION }}" \ | ||
--schedule="${{ steps.globals.outputs.VALIDATOR_SCHEDULE_CRON }}" \ | ||
--time-zone=America/Denver \ | ||
--location=us-central1 \ | ||
--topic="${{ steps.globals.outputs.TOPIC_NAME }}" \ | ||
--message-body='validate' \ | ||
--quiet | ||
fi |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
name: Pull Request Events | ||
|
||
on: | ||
pull_request: | ||
|
||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }} | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
test-unit: | ||
name: Unit Tests | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: ⬇️ Set up code | ||
uses: actions/checkout@v4 | ||
with: | ||
show-progress: false | ||
|
||
- name: 🐍 Set up Python | ||
uses: actions/setup-python@v5 | ||
with: | ||
cache: pip | ||
cache-dependency-path: setup.py | ||
|
||
- name: 📥 Install dependencies | ||
run: | | ||
sudo apt-get update | ||
sudo apt-get install -y libkrb5-dev | ||
|
||
- name: 🏗 Install module | ||
run: pip install .[tests] | ||
|
||
- name: 🧶 Lint | ||
run: ruff check --output-format=github . | ||
|
||
- name: 🧪 Run pytest | ||
run: pytest |
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i believe you still want these or you will have a lot of skipped/failed runs when the if conditions are unmet.