forked from keephq/keep
-
Notifications
You must be signed in to change notification settings - Fork 0
174 lines (150 loc) · 5.65 KB
/
release-workflow-schema.yml
File metadata and controls
174 lines (150 loc) · 5.65 KB
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
name: Release JSON Schema
on:
push:
branches:
- main
paths:
- ".github/workflows/release-workflow-schema.yml"
- "pyproject.toml"
- "keep/providers/**"
- "keep-ui/entities/workflows/model/yaml.schema.ts"
pull_request:
paths:
- ".github/workflows/release-workflow-schema.yml"
- "pyproject.toml"
- "keep/providers/**"
- "keep-ui/entities/workflows/model/yaml.schema.ts"
workflow_dispatch:
env:
PYTHON_VERSION: 3.11
STORAGE_MANAGER_DIRECTORY: /tmp/storage-manager
SCHEMA_REPO_NAME: keephq/keep-workflow-schema
jobs:
generate-schema:
runs-on: ubuntu-latest
permissions:
contents: read
outputs:
version: ${{ steps.get_version.outputs.version }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Extract version from pyproject.toml
id: get_version
run: |
VERSION=$(grep '^version = ' pyproject.toml | sed 's/version = "\(.*\)"/\1/')
echo "version=$VERSION" >> $GITHUB_OUTPUT
- name: Set up Python ${{ env.PYTHON_VERSION }}
uses: actions/setup-python@v4
with:
python-version: "3.11"
- name: Install Poetry
uses: snok/install-poetry@v1
with:
virtualenvs-create: true
virtualenvs-in-project: true
- name: Cache dependencies
id: cache-deps
uses: actions/cache@v4.2.0
with:
path: .venv
key: pydeps-${{ hashFiles('**/poetry.lock') }}
- name: Install dependencies using poetry
run: poetry install --no-interaction --no-root --with dev
- name: Save providers list
run: |
PYTHONPATH="${{ github.workspace }}" poetry run python ./scripts/save_providers_list.py
- name: Set up Node.js 20
uses: actions/setup-node@v3
with:
node-version: 20
cache: "npm"
cache-dependency-path: keep-ui/package-lock.json
- name: Install Node dependencies
working-directory: keep-ui
run: npm ci
- name: Generate JSON Schema
working-directory: keep-ui
run: npm run build:workflow-yaml-json-schema
- name: Upload schema artifact
uses: actions/upload-artifact@v4
with:
name: workflow-schema
path: workflow-yaml-json-schema.json
release-schema:
runs-on: ubuntu-latest
needs: generate-schema
if: ${{ github.event_name != 'pull_request' || !github.event.pull_request.head.repo.fork }}
steps:
- name: Download schema artifact
uses: actions/download-artifact@v4
with:
name: workflow-schema
path: .
- name: Checkout schema repository
uses: actions/checkout@v4
with:
repository: ${{ env.SCHEMA_REPO_NAME }}
token: ${{ secrets.SCHEMA_REPO_PAT }}
path: schema-repo
- name: Set target branch variable
id: set_branch
run: |
if [ "${{ github.event_name }}" = "pull_request" ]; then
echo "branch=${{ github.head_ref }}" >> $GITHUB_OUTPUT
else
echo "branch=${{ github.ref_name }}" >> $GITHUB_OUTPUT
fi
- name: Create or switch to target branch in schema repo
working-directory: schema-repo
run: |
git fetch origin
if git show-ref --verify --quiet refs/heads/${{ steps.set_branch.outputs.branch }}; then
git checkout ${{ steps.set_branch.outputs.branch }}
else
git checkout -b ${{ steps.set_branch.outputs.branch }}
fi
- name: Copy schema to target repository
run: |
cp workflow-yaml-json-schema.json schema-repo/schema.json
# Update schema with version info
jq --arg version "${{ needs.generate-schema.outputs.version }}" \
--arg id "https://raw.githubusercontent.com/${{ env.SCHEMA_REPO_NAME }}/v${{ needs.generate-schema.outputs.version }}/schema.json" \
'. + {version: $version, "$id": $id}' \
schema-repo/schema.json > schema-repo/schema.tmp.json
mv schema-repo/schema.tmp.json schema-repo/schema.json
- name: Check if schema changed
id: check_changes
working-directory: schema-repo
run: |
git add schema.json
if git diff --cached --quiet schema.json; then
echo "changed=false" >> $GITHUB_OUTPUT
else
echo "changed=true" >> $GITHUB_OUTPUT
fi
- name: Commit and push schema
if: steps.check_changes.outputs.changed == 'true'
working-directory: schema-repo
run: |
git config user.name "Keep Schema Bot"
git config user.email "no-reply@keephq.dev"
git commit -m "Release schema v${{ needs.generate-schema.outputs.version }}"
git push origin ${{ steps.set_branch.outputs.branch }}
if [ "${{ steps.set_branch.outputs.branch }}" = "main" ]; then
git tag "v${{ needs.generate-schema.outputs.version }}"
git push origin "v${{ needs.generate-schema.outputs.version }}"
fi
- name: Create GitHub Release
if: steps.check_changes.outputs.changed == 'true' && steps.set_branch.outputs.branch == 'main'
uses: softprops/action-gh-release@v1
with:
repository: ${{ env.SCHEMA_REPO_NAME }}
tag_name: v${{ needs.generate-schema.outputs.version }}
name: Release v${{ needs.generate-schema.outputs.version }}
body: |
Automated release of schema version v${{ needs.generate-schema.outputs.version }}.
env:
GITHUB_TOKEN: ${{ secrets.SCHEMA_REPO_PAT }}