Skip to content

Commit 25d3eaa

Browse files
committed
Add check that version matches tag
1 parent 9d04228 commit 25d3eaa

4 files changed

Lines changed: 84 additions & 19 deletions

File tree

.github/workflows/python-publish.yaml

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,30 +10,34 @@ name: Upload Python Package
1010

1111
on:
1212
release:
13-
types: [published]
13+
types: [ published ]
14+
workflow_dispatch:
1415

1516
permissions:
1617
contents: read
1718

1819
jobs:
1920
deploy:
20-
21+
if: "success() && startsWith(github.ref, 'refs/tags/')"
2122
runs-on: ubuntu-latest
2223

2324
steps:
24-
- uses: actions/checkout@v3
25-
- name: Set up Python
26-
uses: actions/setup-python@v3
27-
with:
28-
python-version: '3.x'
29-
- name: Install dependencies
30-
run: |
31-
python -m pip install --upgrade pip
32-
pip install build
33-
- name: Build package
34-
run: python -m build
35-
- name: Publish package
36-
uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29
37-
with:
38-
user: __token__
39-
password: ${{ secrets.PYPI_API_TOKEN }}
25+
- uses: actions/checkout@v3
26+
- name: Set up Python
27+
uses: actions/setup-python@v3
28+
with:
29+
python-version: '3.9'
30+
- name: Install dependencies
31+
run: |
32+
python -m pip install --upgrade pip
33+
pip install build
34+
- name: check tag
35+
id: check-tag
36+
run: ./tests/check_tag.py
37+
- name: Build package
38+
run: python -m build
39+
- name: Publish package
40+
uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29
41+
with:
42+
user: __token__
43+
password: ${{ secrets.PYPI_API_TOKEN }}

check_tag.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/usr/bin/env/python
2+
# Copyright 2022 Atlan Pte, Ltd
3+
# Copyright [2015-2021] The Apache Software Foundation
4+
#
5+
# Licensed to the Apache Software Foundation (ASF) under one
6+
# or more contributor license agreements. See the NOTICE file
7+
# distributed with this work for additional information
8+
# regarding copyright ownership. The ASF licenses this file
9+
# to you under the Apache License, Version 2.0 (the
10+
# "License"); you may not use this file except in compliance
11+
# with the License. You may obtain a copy of the License at
12+
#
13+
# http://www.apache.org/licenses/LICENSE-2.0
14+
#
15+
# Unless required by applicable law or agreed to in writing, software
16+
# distributed under the License is distributed on an "AS IS" BASIS,
17+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18+
# See the License for the specific language governing permissions and
19+
# limitations under the License.
20+
import io
21+
import os
22+
import re
23+
import sys
24+
25+
26+
def read(file_name):
27+
"""Read a text file and return the content as a string."""
28+
with io.open(
29+
os.path.join(os.path.dirname(__file__), file_name), encoding="utf-8"
30+
) as f:
31+
return f.read()
32+
33+
34+
def main(env_var="GITHUB_REF") -> int:
35+
git_ref = os.getenv(env_var, "none")
36+
tag = re.sub("^refs/tags/v*", "", git_ref.lower())
37+
version = read("version.txt").strip()
38+
if tag == version:
39+
return 0
40+
else:
41+
print(
42+
f"✖ {env_var} env var {git_ref!r} does not match package version: {tag!r} != {version!r}"
43+
)
44+
return 1
45+
46+
47+
if __name__ == "__main__":
48+
sys.exit(main())

setup.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,30 @@
1818
# See the License for the specific language governing permissions and
1919
# limitations under the License.
2020

21+
import io
22+
import os
23+
2124
from setuptools import find_packages, setup
2225

2326
# External dependencies
2427
requirements = ["requests>=2.24", "pydantic>=1.10.4", "jinja2>=3.1.2"]
2528

29+
30+
def read(file_name):
31+
"""Read a text file and return the content as a string."""
32+
with io.open(
33+
os.path.join(os.path.dirname(__file__), file_name), encoding="utf-8"
34+
) as f:
35+
return f.read()
36+
37+
2638
long_description = ""
2739
with open("README.md", "r") as fh:
2840
long_description = fh.read()
2941

3042
setup(
3143
name="pyatlan",
32-
version="0.0.17",
44+
version=read("version.txt"),
3345
author="Atlan Technologies Pvt Ltd",
3446
author_email="engineering@atlan.com",
3547
description="Atlan Python Client",

version.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0.0.18

0 commit comments

Comments
 (0)