-
Notifications
You must be signed in to change notification settings - Fork 1
86 lines (76 loc) · 2.67 KB
/
notes-sync.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
name: Sync new Hubspot notes to Slack
on:
workflow_dispatch:
inputs:
page_size:
description: Page size for API requests
required: false
default: 10
type: number
max_pages:
description: Maximum number of pages to request
required: false
default: 1
type: number
last_note_id:
description: The ID of the last note that was processed
required: false
type: string
slack_channel:
description: The ID of the Cal-ITP Slack channel to post the message(s) to
type: string
required: false
schedule:
# every hour at HH:10
- cron: 35 * * * *
jobs:
sync-notes-to-slack:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
cache: pip
cache-dependency-path: "pyproject.toml"
- name: Install tooling
run: pip install -e .[hubspot,notes]
- name: Get last_note_id from workflow input
if: inputs.last_note_id
run: echo ${{ inputs.last_note_id }} > last_note_id
- name: Get last_note_id from repository variable
if: github.event.schedule
run: echo ${{ vars.HUBSPOT_LAST_NOTE_ID }} > last_note_id
- name: Download newer notes
id: download
run: |
python notes/download.py
echo "last_note_id=$(cat last_note_id)" >> $GITHUB_OUTPUT
env:
HUBSPOT_ACCESS_TOKEN: ${{ secrets.HUBSPOT_NOTES_ACCESS_TOKEN }}
HUBSPOT_MAX_PAGES: ${{ inputs.max_pages || vars.HUBSPOT_MAX_PAGES }}
HUBSPOT_PAGE_SIZE: ${{ inputs.page_size || vars.HUBSPOT_PAGE_SIZE }}
- name: Post a message for each downloaded note
run: python notes/post.py
env:
SLACK_ACCESS_TOKEN: ${{ secrets.SLACK_ACCESS_TOKEN }}
SLACK_CHANNEL_ID: ${{ inputs.slack_channel || vars.SLACK_CHANNEL_ID }}
SLACK_RATE_LIMIT: ${{ vars.SLACK_RATE_LIMIT }}
HUBSPOT_INSTANCE_ID: ${{ secrets.HUBSPOT_INSTANCE_ID }}
- uses: actions/github-script@v7
name: Update last_note_id repository variable
if: github.event.schedule
env:
LAST_NOTE_ID: ${{steps.download.outputs.last_note_id}}
with:
github-token: ${{ secrets.GH_TOKEN_REPO_VARS }}
script: |
const { LAST_NOTE_ID } = process.env;
github.rest.actions.updateRepoVariable({
owner: context.repo.owner,
repo: context.repo.repo,
name: "HUBSPOT_LAST_NOTE_ID",
value: LAST_NOTE_ID,
});