Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobdadams authored Nov 21, 2024
0 parents commit 5488f86
Show file tree
Hide file tree
Showing 19 changed files with 824 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[run]
omit =
# files to omit from coverage. should be sample files etc
# */connection_sample.py

[report]
exclude_lines =
# Don't complain if non-runnable code isn't run:
if __name__ == .__main__.
10 changes: 10 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
root = true

[*.py]
indent_size = 4

[*]
indent_style = space
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
21 changes: 21 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
version: 2
updates:
- package-ecosystem: pip
directory: /
schedule:
interval: monthly
groups:
safe-dependencies:
update-types: ['minor', 'patch']
major-dependencies:
update-types: ['major']
commit-message:
prefix: deps
prefix-development: deps(dev)
- package-ecosystem: github-actions
directory: /
schedule:
interval: monthly
groups:
ci-dependencies:
dependency-type: 'production'
180 changes: 180 additions & 0 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
name: Push Events

on:
push:
branches:
- main
- dev
pull_request:
branches:
- main
- dev

env:
CLOUD_FUNCTION_MEMORY: 512M
CLOUD_FUCNTION_RUN_TIMEOUT: 240s
SCHEDULE_NAME: monday-morning
SCHEDULE_CRON: 0 9 * * 1
SCHEDULE_DESCRIPTION: "Trigger the projectname-skid bot once a week on monday morning"

concurrency:
group: "${{ github.head_ref || github.ref }}"
cancel-in-progress: true

jobs:
test:
name: Setup and Test
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
show-progress: false

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.11
cache: pip
cache-dependency-path: setup.py

- name: Install libkrb5 for Kerberos on Linux
run: |
sudo apt-get update
sudo apt-get install -y libkrb5-dev
- 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

- 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: ${{ secrets.IDENTITY_PROVIDER }}
service_account: ${{ secrets.SERVICE_ACCOUNT_EMAIL }}

- name: 🚀 Deploy to Cloud Function
id: deploy
uses: google-github-actions/deploy-cloud-functions@v3
timeout-minutes: 15
with:
name: projectname-skid
runtime: python311
entry_point: subscribe
source_dir: src/projectname
service_account: cloud-function-sa@${{ secrets.PROJECT_ID }}.iam.gserviceaccount.com
event_trigger_type: google.cloud.pubsub.topic.v1.messagePublished
event_trigger_pubsub_topic: projects/${{ secrets.PROJECT_ID }}/topics/${{ env.SCHEDULE_NAME }}-topic
memory: ${{ env.CLOUD_FUNCTION_MEMORY }}
service_timeout: ${{ env.CLOUD_FUNCTION_RUN_TIMEOUT }}
environment_variables: STORAGE_BUCKET=${{secrets.STORAGE_BUCKET}}
secrets: |
/secrets/app/secrets.json=${{secrets.PROJECT_ID}}/skid-secrets
max_instance_count: 1
event_trigger_retry: false

- name: 📥 Create PubSub topic
run: |
if [ ! "$(gcloud pubsub topics list | grep $SCHEDULE_NAME-topic)" ]; then
gcloud pubsub topics create $SCHEDULE_NAME-topic --quiet
fi
- name: 🕰️ Create Cloud Scheduler
run: |
for i in $(gcloud scheduler jobs list --location=us-central1 --uri); do
gcloud scheduler jobs delete $i --quiet
done
gcloud scheduler jobs create pubsub $SCHEDULE_NAME \
--description="$SCHEDULE_DESCRIPTION" \
--schedule="$SCHEDULE_CRON" \
--time-zone=America/Denver \
--location=us-central1 \
--topic=$SCHEDULE_NAME-topic \
--message-body='foo' \
--quiet
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

- 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: ${{ secrets.IDENTITY_PROVIDER }}
service_account: ${{ secrets.SERVICE_ACCOUNT_EMAIL }}

- name: 🚀 Deploy to Cloud Function
id: deploy
uses: google-github-actions/deploy-cloud-functions@v3
timeout-minutes: 15
with:
name: projectname-skid
runtime: python311
entry_point: main
source_dir: src/projectname
service_account: cloud-function-sa@${{ secrets.PROJECT_ID }}.iam.gserviceaccount.com
event_trigger_type: google.cloud.pubsub.topic.v1.messagePublished
event_trigger_pubsub_topic: projects/${{ secrets.PROJECT_ID }}/topics/${{ env.SCHEDULE_NAME }}-topic
memory: ${{ env.CLOUD_FUNCTION_MEMORY }}
service_timeout: ${{ env.CLOUD_FUNCTION_RUN_TIMEOUT }}
environment_variables: STORAGE_BUCKET=${{secrets.STORAGE_BUCKET}}
secrets: |
/secrets/ftp/known_hosts=${{secrets.PROJECT_ID}}/known_hosts
/secrets/app/secrets.json=${{secrets.PROJECT_ID}}/skid-secrets
max_instance_count: 1
event_trigger_retry: false

- name: 📥 Create PubSub topic
run: |
if [ ! "$(gcloud pubsub topics list | grep $SCHEDULE_NAME-topic)" ]; then
gcloud pubsub topics create $SCHEDULE_NAME-topic --quiet
fi
- name: 🕰️ Create Cloud Scheduler
run: |
for i in $(gcloud scheduler jobs list --location=us-central1 --uri); do
gcloud scheduler jobs delete $i --quiet
done
gcloud scheduler jobs create pubsub $SCHEDULE_NAME \
--description="$SCHEDULE_DESCRIPTION" \
--schedule="$SCHEDULE_CRON" \
--time-zone=America/Denver \
--location=us-central1 \
--topic=$SCHEDULE_NAME-topic \
--message-body='{"run": "now"}' \
--quiet
35 changes: 35 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
secrets.json
sheets-sa.json

*.py[cod]

# Packages
.eggs/
*.egg
*.egg-info
dist
build
eggs
parts
bin
var
sdist
develop-eggs
.installed.cfg
lib
lib64
__pycache__

# Installer logs
pip-log.txt

*.pyt.xml
*.csv.xml
arc.dir
.pytest_cache
__pycache__

.env/
.DS_Store
cov.xml
.coverage
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.11
17 changes: 17 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=827846 to learn about workspace recommendations.
// Extension identifier format: ${publisher}.${name}. Example: vscode.csharp
// List of extensions which should be recommended for users of this workspace.
"recommendations": [
"editorconfig.editorconfig",
"njpwerner.autodocstring",
"ms-python.black-formatter",
"ms-python.vscode-pylance",
"ms-python.python",
"donjayamanne.python-environment-manager",
"charliermarsh.ruff",
"tamasfe.even-better-toml"
],
// List of extensions recommended by VS Code that should not be recommended for users of this workspace.
"unwantedRecommendations": []
}
50 changes: 50 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"cSpell.words": [
"agrc",
"arcgis",
"arcpy",
"Codecov",
"finditer",
"getenv",
"instafail",
"mapserv",
"metatable",
"mssql",
"ODBC",
"oidc",
"opensgid",
"palletjack",
"pgsql",
"psycopg",
"pygsheets",
"pyodbc",
"pytest",
"rindex",
"sgid",
"UGRC",
"venv",
"worknote"
],
"editor.formatOnSave": true,
"editor.rulers": [
120
],
"coverage-gutters.showGutterCoverage": false,
"coverage-gutters.showLineCoverage": true,
"coverage-gutters.showRulerCoverage": false,
"coverage-gutters.highlightdark": "rgb(61, 153, 112, .05)",
"coverage-gutters.noHighlightDark": "rgb(255, 65, 54, .05)",
"coverage-gutters.partialHighlightDark": "rgb(255, 133, 27, .05)",
"python.languageServer": "Pylance",
"python.testing.pytestEnabled": true,
"python.testing.pytestArgs": [
"--no-cov"
],
"editor.codeActionsOnSave": {
"source.organizeImports": "explicit"
},
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter",
"editor.formatOnSave": true
}
}
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2022 UGRC

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Loading

0 comments on commit 5488f86

Please sign in to comment.