Skip to content

Commit fdd6519

Browse files
authored
Merge pull request #20 from fileames/combined_release
Combined Release Workflow
2 parents afc8c24 + 483d11a commit fdd6519

File tree

1 file changed

+175
-19
lines changed

1 file changed

+175
-19
lines changed

.github/workflows/_release.yml

Lines changed: 175 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,44 +6,200 @@
66
# separate terms of service, privacy policy, and support
77
# documentation.
88

9-
name: Upload Python Package
9+
name: Build and Publish Python Package
1010

1111
on:
1212
release:
1313
types: [published]
1414
workflow_dispatch:
15+
inputs:
16+
working-directory:
17+
required: true
18+
type: string
19+
default: 'libs/oci'
1520

16-
permissions:
17-
contents: read
21+
env:
22+
PYTHON_VERSION: "3.11"
23+
POETRY_VERSION: "1.7.1"
1824

1925
jobs:
20-
build-n-publish:
21-
name: Build and publish Python 🐍 distribution 📦 to PyPI
26+
build:
27+
if: github.ref == 'refs/heads/main'
2228
runs-on: ubuntu-latest
23-
defaults:
24-
run:
25-
working-directory: libs/oci # Set default for all steps
26-
environment:
27-
name: pypi
28-
url: https://pypi.org/p/langchain-oci
29+
30+
outputs:
31+
pkg-name: ${{ steps.check-version.outputs.pkg-name }}
32+
version: ${{ steps.check-version.outputs.version }}
33+
2934
steps:
3035
- uses: actions/checkout@v4
36+
37+
- name: Set up Python + Poetry ${{ env.POETRY_VERSION }}
38+
uses: "./.github/actions/poetry_setup"
39+
with:
40+
python-version: ${{ env.PYTHON_VERSION }}
41+
poetry-version: ${{ env.POETRY_VERSION }}
42+
working-directory: ${{ inputs.working-directory }}
43+
cache-key: release
44+
45+
- name: Build project for distribution
46+
run: poetry build
47+
working-directory: ${{ inputs.working-directory }}
48+
49+
- name: Upload build
50+
uses: actions/upload-artifact@v4
51+
with:
52+
name: dist
53+
path: ${{ inputs.working-directory }}/dist/
54+
55+
- name: Check Version
56+
id: check-version
57+
shell: bash
58+
working-directory: ${{ inputs.working-directory }}
59+
run: |
60+
echo pkg-name="$(poetry version | cut -d ' ' -f 1)" >> $GITHUB_OUTPUT
61+
echo version="$(poetry version --short)" >> $GITHUB_OUTPUT
62+
63+
test-pypi-publish:
64+
needs: build
65+
runs-on: ubuntu-latest
66+
environment:
67+
name: testpypi
68+
url: https://test.pypi.org/project/${{ needs.build.outputs.pkg-name }}/
69+
steps:
70+
- name: Download build artifacts
71+
uses: actions/download-artifact@v4
72+
with:
73+
name: dist
74+
path: ${{ inputs.working-directory }}/dist/
75+
3176
- name: Set up Python
3277
uses: actions/setup-python@v5
3378
with:
34-
python-version: "3.x"
35-
- name: Build distribution 📦
79+
python-version: '3.x'
80+
81+
- name: Publish distribution 📦 to TestPyPI
82+
env:
83+
TWINE_USERNAME: __token__
84+
TWINE_PASSWORD: ${{ secrets.GH_LC_OCI_TESTPYPI_TOKEN }}
3685
run: |
37-
pip install build
38-
python -m build
39-
- name: Validate
86+
pip install twine
87+
twine upload --repository-url https://test.pypi.org/legacy/ ${{ inputs.working-directory }}/dist/* -u $TWINE_USERNAME -p $TWINE_PASSWORD
88+
89+
pre-release-checks:
90+
needs:
91+
- build
92+
- test-pypi-publish
93+
runs-on: ubuntu-latest
94+
steps:
95+
- uses: actions/checkout@v4
96+
97+
- name: Set up Python + Poetry ${{ env.POETRY_VERSION }}
98+
uses: "./.github/actions/poetry_setup"
99+
with:
100+
python-version: ${{ env.PYTHON_VERSION }}
101+
poetry-version: ${{ env.POETRY_VERSION }}
102+
working-directory: ${{ inputs.working-directory }}
103+
104+
- name: Import published package
105+
shell: bash
106+
working-directory: ${{ inputs.working-directory }}
107+
env:
108+
PKG_NAME: ${{ needs.build.outputs.pkg-name }}
109+
VERSION: ${{ needs.build.outputs.version }}
110+
# Here we use:
111+
# - The default regular PyPI index as the *primary* index, meaning
112+
# that it takes priority (https://pypi.org/simple)
113+
# - The test PyPI index as an extra index, so that any dependencies that
114+
# are not found on test PyPI can be resolved and installed anyway.
115+
# (https://test.pypi.org/simple). This will include the PKG_NAME==VERSION
116+
# package because VERSION will not have been uploaded to regular PyPI yet.
117+
# - attempt install again after 5 seconds if it fails because there is
118+
# sometimes a delay in availability on test pypi
119+
run: |
120+
poetry run pip install \
121+
--extra-index-url https://test.pypi.org/simple/ \
122+
"$PKG_NAME==$VERSION" || \
123+
( \
124+
sleep 5 && \
125+
poetry run pip install \
126+
--extra-index-url https://test.pypi.org/simple/ \
127+
"$PKG_NAME==$VERSION" \
128+
)
129+
130+
# Replace all dashes in the package name with underscores,
131+
# since that's how Python imports packages with dashes in the name.
132+
IMPORT_NAME="$(echo "$PKG_NAME" | sed s/-/_/g)"
133+
134+
poetry run python -c "import $IMPORT_NAME; print(dir($IMPORT_NAME))"
135+
136+
- name: Import test dependencies
137+
run: poetry install --with test,test_integration
138+
working-directory: ${{ inputs.working-directory }}
139+
140+
# Overwrite the local version of the package with the test PyPI version.
141+
- name: Import published package (again)
142+
working-directory: ${{ inputs.working-directory }}
143+
shell: bash
144+
env:
145+
PKG_NAME: ${{ needs.build.outputs.pkg-name }}
146+
VERSION: ${{ needs.build.outputs.version }}
147+
run: |
148+
poetry run pip install \
149+
--extra-index-url https://test.pypi.org/simple/ \
150+
"$PKG_NAME==$VERSION"
151+
152+
- name: Run unit tests
153+
run: make tests
154+
working-directory: ${{ inputs.working-directory }}
155+
156+
- name: Run integration tests
157+
run: make integration_tests
158+
working-directory: ${{ inputs.working-directory }}
159+
160+
- name: Get minimum versions
161+
working-directory: ${{ inputs.working-directory }}
162+
id: min-version
163+
run: |
164+
poetry run pip install packaging
165+
min_versions="$(poetry run python $GITHUB_WORKSPACE/.github/scripts/get_min_versions.py pyproject.toml)"
166+
echo "min-versions=$min_versions" >> "$GITHUB_OUTPUT"
167+
echo "min-versions=$min_versions"
168+
169+
- name: Run unit tests with minimum dependency versions
170+
if: ${{ steps.min-version.outputs.min-versions != '' }}
171+
env:
172+
MIN_VERSIONS: ${{ steps.min-version.outputs.min-versions }}
40173
run: |
41-
pip install dist/*.whl
42-
python -c "import langchain_oci;"
174+
poetry run pip install $MIN_VERSIONS
175+
make tests
176+
working-directory: ${{ inputs.working-directory }}
177+
178+
publish:
179+
needs:
180+
- build
181+
- test-pypi-publish
182+
- pre-release-checks
183+
runs-on: ubuntu-latest
184+
environment:
185+
name: pypi
186+
url: https://pypi.org/p/${{ needs.build.outputs.pkg-name }}
187+
steps:
188+
- name: Download build artifacts
189+
uses: actions/download-artifact@v4
190+
with:
191+
name: dist
192+
path: ${{ inputs.working-directory }}/dist/
193+
194+
- name: Set up Python
195+
uses: actions/setup-python@v5
196+
with:
197+
python-version: '3.x'
198+
43199
- name: Publish distribution 📦 to PyPI
44200
env:
45201
TWINE_USERNAME: __token__
46202
TWINE_PASSWORD: ${{ secrets.GH_LC_OCI_PYPI_TOKEN }}
47203
run: |
48204
pip install twine
49-
twine upload dist/* -u $TWINE_USERNAME -p $TWINE_PASSWORD
205+
twine upload ${{ inputs.working-directory }}/dist/* -u $TWINE_USERNAME -p $TWINE_PASSWORD

0 commit comments

Comments
 (0)