Skip to content

Commit

Permalink
feat: add schedules for sapphire ceremony reminders
Browse files Browse the repository at this point in the history
  • Loading branch information
amonkhouse committed Apr 8, 2024
1 parent 9962790 commit a0bec3b
Show file tree
Hide file tree
Showing 7 changed files with 123 additions and 1 deletion.
51 changes: 51 additions & 0 deletions .github/workflows/sapphire-on-call-retro.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Sapphire On Call Retro

on:
workflow_dispatch:
schedule:
- cron: "45 14 * * THURS"

jobs:
check_and_notify:
runs-on: ubuntu-latest
outputs:
should_run: ${{ steps.check_run_condition.outputs.should_run }}
steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Check if retro is today
id: check_run_condition
run: |
result=$(python3 sapphire/utils/is_retro_today.py)
echo "::set-output name=should_run::$result"
sapphire-on-call-retro:
needs: check_and_notify
if: needs.check_and_notify.outputs.should_run == 'true'
runs-on: ubuntu-latest
timeout-minutes: 10

steps:
- name: Setup Node.JS
uses: actions/setup-node@v2
with:
node-version: "12"

- name: Install Dependencies
run: npm install --global @artsy/cli

- name: Run CLI
id: cli
run: echo "PAYLOAD=$(artsy scheduled:sapphire-on-call-retro)" >> "$GITHUB_OUTPUT"
env:
OPSGENIE_API_KEY: ${{ secrets.OPSGENIE_API_KEY }}
SLACK_WEB_API_TOKEN: ${{ secrets.SLACK_WEB_API_TOKEN }}

- name: Standup Reminder > Slack
uses: 8398a7/action-slack@v3
with:
status: custom
custom_payload: ${{steps.cli.outputs.PAYLOAD}}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
35 changes: 35 additions & 0 deletions .github/workflows/sapphire-on-call.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Sapphire On Call

on:
workflow_dispatch:
schedule:
- cron: "45 14 * * MON"

jobs:
sapphire-on-call:
runs-on: ubuntu-latest
timeout-minutes: 10

steps:
- name: Setup Node.JS
uses: actions/setup-node@v2
with:
node-version: "12"

- name: Install Dependencies
run: npm install --global @artsy/cli

- name: Run CLI
id: cli
run: echo "PAYLOAD=$(artsy scheduled:sapphire-on-call)" >> "$GITHUB_OUTPUT"
env:
OPSGENIE_API_KEY: ${{ secrets.OPSGENIE_API_KEY }}
SLACK_WEB_API_TOKEN: ${{ secrets.SLACK_WEB_API_TOKEN }}

- name: Standup Reminder > Slack
uses: 8398a7/action-slack@v3
with:
status: custom
custom_payload: ${{steps.cli.outputs.PAYLOAD}}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,8 @@ node_modules/

# macOS
.DS_Store

# python
__pycache__/
.pytest_cache/
.python-version
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# joule

Helpful artsy engineering bot
Helpful artsy engineering bot to send scheduled Slack messages.

Commands are added to [artsy/cli](https://github.com/artsy/cli) then called and scheduled under `.github/workflows`.

## Setup

Expand Down
2 changes: 2 additions & 0 deletions sapphire/test/test-requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
freezegun==1.4.0
pytest==8.1.1
12 changes: 12 additions & 0 deletions sapphire/test/test_is_retro_today.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from freezegun import freeze_time
from utils.is_retro_today import is_retro_today


@freeze_time("2024-04-11")
def test_is_retro_today_returns_false_when_not_retro():
assert not is_retro_today()


@freeze_time("2024-04-18")
def test_is_retro_today_returns_true_when_retro():
assert is_retro_today()
15 changes: 15 additions & 0 deletions sapphire/utils/is_retro_today.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from datetime import datetime


def is_retro_today():
start_date = datetime(2024, 4, 4)
today = datetime.now()
week_diff = (today - start_date).days / 7
return week_diff % 2 == 0


if __name__ == "__main__":
if is_retro_today():
print("true")
else:
print("false")

0 comments on commit a0bec3b

Please sign in to comment.