Skip to content

Commit 4df0d61

Browse files
authored
Merge pull request #165 from opsmill/bkr-new-release-cicd
New release CICD
2 parents 6d5e51b + 99138f5 commit 4df0d61

File tree

5 files changed

+164
-32
lines changed

5 files changed

+164
-32
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ jobs:
112112
./actionlint -color
113113
shell: bash
114114
env:
115-
SHELLCHECK_OPTS: --exclude=SC2086 --exclude=SC2046 --exclude=SC2004
115+
SHELLCHECK_OPTS: --exclude=SC2086 --exclude=SC2046 --exclude=SC2004 --exclude=SC2129
116116

117117

118118
unit-tests:

.github/workflows/publish-python-sdk.yml renamed to .github/workflows/publish-pypi.yml

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,32 @@
11
---
2-
name: Publish Infrahub Python SDK
2+
# yamllint disable rule:truthy
3+
name: Publish Infrahub SDK Package
34

4-
on: # yamllint disable rule:truthy
5-
push:
6-
tags:
7-
- "v*"
5+
on:
6+
workflow_dispatch:
7+
inputs:
8+
runs-on:
9+
description: "The OS to run the job on"
10+
required: false
11+
default: "ubuntu-22.04"
12+
type: string
13+
publish:
14+
type: boolean
15+
description: Whether to publish the package to Pypi
16+
required: false
17+
default: false
18+
workflow_call:
19+
inputs:
20+
runs-on:
21+
description: "The OS to run the job on"
22+
required: false
23+
default: "ubuntu-22.04"
24+
type: string
25+
publish:
26+
type: boolean
27+
description: Whether to publish the package to Pypi
28+
required: false
29+
default: false
830

931
jobs:
1032
publish_to_pypi:
@@ -25,6 +47,8 @@ jobs:
2547

2648
- name: "Check out repository code"
2749
uses: "actions/checkout@v4"
50+
with:
51+
submodules: true
2852

2953
- name: "Cache poetry venv"
3054
uses: "actions/cache@v4"
@@ -47,4 +71,5 @@ jobs:
4771
run: "ls -la dist/"
4872

4973
- name: "Poetry push PyPI"
74+
if: ${{ inputs.publish }}
5075
run: "poetry publish"

.github/workflows/release.yml

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
---
2+
# yamllint disable rule:truthy rule:line-length
3+
name: New Release
4+
5+
on:
6+
release:
7+
types:
8+
- published
9+
10+
jobs:
11+
check_release:
12+
runs-on: ubuntu-22.04
13+
outputs:
14+
is_prerelease: ${{ steps.release.outputs.is_prerelease }}
15+
is_devrelease: ${{ steps.release.outputs.is_devrelease }}
16+
version: ${{ steps.release.outputs.version }}
17+
major_minor_version: ${{ steps.release.outputs.major_minor_version }}
18+
latest_tag: ${{ steps.release.outputs.latest_tag }}
19+
steps:
20+
- name: "Check out repository code"
21+
uses: "actions/checkout@v4"
22+
with:
23+
submodules: true
24+
25+
- name: "Set up Python"
26+
uses: "actions/setup-python@v5"
27+
with:
28+
python-version: "3.12"
29+
30+
- name: "Install Poetry"
31+
uses: "snok/install-poetry@v1"
32+
with:
33+
virtualenvs-create: true
34+
virtualenvs-in-project: true
35+
installer-parallel: true
36+
37+
- name: "Setup Python environment"
38+
run: |
39+
poetry config virtualenvs.create true --local
40+
poetry env use 3.12
41+
- name: "Install dependencies"
42+
run: "poetry install --no-interaction --no-ansi"
43+
44+
- name: "Check prerelease type"
45+
id: release
46+
run: |
47+
echo is_prerelease=$(poetry run python -c "from packaging.version import Version; print(int(Version('$(poetry version -s)').is_prerelease))") >> "$GITHUB_OUTPUT"
48+
echo is_devrelease=$(poetry run python -c "from packaging.version import Version; print(int(Version('$(poetry version -s)').is_devrelease))") >> "$GITHUB_OUTPUT"
49+
echo "version=$(poetry version -s)" >> "$GITHUB_OUTPUT"
50+
echo major_minor_version=$(poetry run python -c "from packaging.version import Version; print(f\"{Version('$(poetry version -s)').major}.{Version('$(poetry version -s)').minor}\")") >> "$GITHUB_OUTPUT"
51+
echo latest_tag=$(curl -L \
52+
-H "Accept: application/vnd.github+json" \
53+
-H "Authorization: Bearer ${{ github.token }}" \
54+
-H "X-GitHub-Api-Version: 2022-11-28" \
55+
https://api.github.com/repos/${{ github.repository }}/releases/latest \
56+
| jq -r '.tag_name') >> "$GITHUB_OUTPUT"
57+
58+
- name: Check tag version
59+
if: github.event.release.tag_name != format('infrahub-v{0}', steps.release.outputs.version)
60+
run: |
61+
echo "Tag version does not match python project version"
62+
exit 1
63+
64+
- name: Check prerelease and project version
65+
if: github.event.release.prerelease == true && steps.release.outputs.is_prerelease == 0 && steps.release.outputs.is_devrelease == 0
66+
run: |
67+
echo "Cannot pre-release a non pre-release or non dev-release version (${{ steps.release.outputs.version }})"
68+
exit 1
69+
70+
- name: Check release and project version
71+
if: github.event.release.prerelease == false && (steps.release.outputs.is_prerelease == 1 || steps.release.outputs.is_devrelease == 1)
72+
run: |
73+
echo "Cannot release a pre-release or dev-release version (${{ steps.release.outputs.version }})"
74+
exit 1
75+
76+
publish-pypi:
77+
needs: check_release
78+
uses: ./.github/workflows/publish-pypi.yml
79+
secrets: inherit
80+
with:
81+
publish: true
82+
83+
update-submodule:
84+
needs: check_release
85+
uses: ./.github/workflows/update-submodule.yml
86+
secrets: inherit
87+
with:
88+
version: ${{ github.ref_name }}

.github/workflows/trigger.yml

Lines changed: 0 additions & 26 deletions
This file was deleted.
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
---
2+
# yamllint disable rule:truthy
3+
name: Trigger Submodule update
4+
5+
on:
6+
workflow_dispatch:
7+
inputs:
8+
runs-on:
9+
description: "The OS to run the job on"
10+
required: false
11+
default: "ubuntu-22.04"
12+
type: string
13+
version:
14+
type: string
15+
required: false
16+
description: The string to extract semver from.
17+
default: ''
18+
workflow_call:
19+
inputs:
20+
runs-on:
21+
description: "The OS to run the job on"
22+
required: false
23+
default: "ubuntu-22.04"
24+
type: string
25+
version:
26+
type: string
27+
required: false
28+
description: The string to extract semver from.
29+
default: ''
30+
31+
jobs:
32+
trigger-submodule:
33+
runs-on: ubuntu-22.04
34+
steps:
35+
- name: Checkout code
36+
uses: actions/checkout@v4
37+
38+
- name: Trigger submodule update
39+
run: |
40+
echo "${{ inputs.version }}"
41+
curl -X POST \
42+
-H "Authorization: token ${{ secrets.GH_UPDATE_PACKAGE_OTTO }}" \
43+
-H "Accept: application/vnd.github.v3+json" \
44+
https://api.github.com/repos/opsmill/infrahub/dispatches \
45+
-d "{\"event_type\":\"trigger-submodule-update\", \"client_payload\": {\"version\": \"${{ inputs.version }}\"}}"

0 commit comments

Comments
 (0)