Repository navigation
109 lines (93 loc) · 4.17 KB
/
Copy pathfetch-schema.yaml
File metadata and controls
109 lines (93 loc) · 4.17 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
name: Fetch Schema
on:
workflow_dispatch:
inputs:
version:
description: 'New schema version number'
required: true
type: number
env:
NEW_VERSION: ${{ inputs.version }}
BRANCH_NAME: schema-${{ inputs.version }}
jobs:
update_to_schema_version:
runs-on: ubuntu-latest
permissions:
# permission to commit and push changed files
contents: write
# permission to create a pull request
pull-requests: write
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Read current schema version
run: |
echo "OLD_VERSION=$(sed -nE "s/^\s+version: '([0-9]+)'$/\1/p" src/main/resources/api.yaml)" >> "$GITHUB_ENV"
- name: Ensure new version is an upgrade
if: ${{ env.NEW_VERSION <= env.OLD_VERSION }}
run: |
echo "::error title=Invalid update version::${{ env.NEW_VERSION }} <= ${{ env.OLD_VERSION}}"
exit 1
# Verify branch doesn't exist
- name: Ensure branch doesn't exist
run: |
EXISTS=$(git ls-remote --heads origin refs/heads/${{ env.BRANCH_NAME }} | wc -l)
if [ $EXISTS -eq 1 ] ; then
echo "::error title=Invalid update version::Branch ${{ env.BRANCH_NAME }} already exists"
exit 1
fi
- name: Checkout schema
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
repository: 'inventree/schema'
path: 'schema'
fetch-depth: 0
- name: Verify schema exists
run: |
if [ ! -d "schema/export/${{ env.NEW_VERSION }}" ]; then
echo "::error title=Invalid update version::${{ env.NEW_VERSION }} not found"
exit 1
fi
- name: Read original commit hash and date
run: |
cd schema
git log export/${{ env.NEW_VERSION }}/api.yaml | sed -nE 's|^\s+Update API schema for [0-9]+ / (.*)$|\1|p' > ../.github/inventree_test_hash.txt
echo "COMMIT_DATE=$(git log -1 --format="%ci" export/${{ env.NEW_VERSION }}/api.yaml)" >> $GITHUB_ENV
- name: Checkout inventree demo dataset
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
repository: 'inventree/demo-dataset'
path: 'demo-dataset'
fetch-depth: 0
- name: Detatch to demo data prior to schema date
run: |
cd demo-dataset
git checkout $(git log -1 --format="%H" --until="${{ env.COMMIT_DATE }}")
git log -1 --format="%H" > ../.github/demo-dataset_hash.txt
- name: Collect files
run: |
sed -iE "s/${{ env.OLD_VERSION }}-SNAPSHOT/${{ env.NEW_VERSION }}-SNAPSHOT/g" pom.xml
cp schema/export/${{ env.NEW_VERSION }}/api.yaml src/main/resources/api.yaml
cp demo-dataset/inventree_data.json src/test/resources/inventree_data.json
- name: Commit and push
uses: stefanzweifel/git-auto-commit-action@d0b01107b5db882071f96de5dd4b54961ea93f4c # v7.2.1
with:
branch: '${{ env.BRANCH_NAME }}'
create_branch: true
file_pattern: 'pom.xml .github/inventree_test_hash.txt .github/demo-dataset_hash.txt src/*'
commit_message: 'Update to schema ${{ env.NEW_VERSION }}'
- name: Checkout inventree
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
repository: 'inventree/InvenTree'
path: 'InvenTree'
- name: Build PR body text
run: |
echo "**v${{ env.NEW_VERSION }}**" > pr_body.md
# delete (don't print) from line 1 to version header, then from blank line to end
sed '1,/^v${{ env.NEW_VERSION }}.*$/d;/^$/,$d' InvenTree/src/backend/InvenTree/InvenTree/api_version.py | sed 's/ //' >> pr_body.md
echo "" >> pr_body.md
echo "Automatically generated, check schema diff for needed changes" >> pr_body.md
- name: Create pull request
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: gh pr create --draft -B main -H ${{ env.BRANCH_NAME }} --title 'Update to schema version ${{ inputs.version }}' --body-file pr_body.md