-
Notifications
You must be signed in to change notification settings - Fork 0
62 lines (54 loc) · 2.18 KB
/
ci.yaml
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
name: CI
on:
push:
jobs:
lint:
name: Lint Jinja Templates
runs-on: ubuntu-latest
steps:
- name: Checkout git repo
uses: actions/checkout@v4
- name: Install j2lint
run: pip install j2lint
- name: Run j2lint
run: |
j2lint *.j2 -w S6 --json > /tmp/lint.json || LINT_EXIT=$?
jq -r '(.ERRORS | map(. + { type: "error" })) + (.WARNINGS | map(. + { type: "warning" })) | .[] | "::\(.type) file=\(.filename),line=\(.line_number),title=\(.id)::\(.message)"' < /tmp/lint.json
exit $LINT_EXIT
sync:
name: Netbox Sync
runs-on: ubuntu-latest
needs: lint
steps:
- uses: actions/github-script@v7
with:
script: |
const apiBase = "https://netbox.freifunk-duesseldorf.de/api/core/data-sources/"
const httpOpts = {
headers: {
Authorization: "Token ${{ secrets.NETBOX_API_TOKEN }}",
},
}
const repoURL = "https://github.com/${{ github.repository }}"
// find datasource matching branch
const dataSourceResp = await fetch(`${apiBase}?source_url=${encodeURIComponent(repoURL)}`, httpOpts)
if (!dataSourceResp.ok) {
throw new Error(`Invalid HTTP response: ${dataSourceResp.status}`)
}
const { results: dataSources, count } = await dataSourceResp.json()
let expectedBranch = "${{ github.ref_name }}"
if ("${{ github.event.repository.default_branch }}" == expectedBranch) {
expectedBranch = ""
}
const dataSource = dataSources.find(s => s.parameters.branch == expectedBranch)
if (!dataSource) {
if (expectedBranch == "") {
throw new Error("Data Source to sync not found")
}
console.warn("Couldn't find data source to sync. Ignoring since not on default branch.")
return
}
const syncResp = await fetch(`${dataSource.url}/sync/`, { ...httpOpts, method: "POST" })
if (!syncResp.ok) {
throw new Error(`Invalid HTTP response: ${syncResp.status}`)
}