1- # name: Publish Casp CLI to PyPI
2-
3- # on:
4- # release:
5- # types: [published]
6-
7- # jobs:
8- # publish-pypi:
9- # name: Build and Publish CLI
10- # runs-on: ubuntu-latest
11- # permissions:
12- # contents: read
13- # steps:
14- # - uses: actions/checkout@v4
15- # with:
16- # fetch-depth: 0
17-
18- # - name: Check for changes in cli/casp
19- # id: check_changes
20- # run: |
21- # PREV_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || true)
22-
23- # if [ -z "$PREV_TAG" ]; then
24- # echo "No previous tag found (likely first release). Publishing..."
25- # echo "changed=true" >> "$GITHUB_OUTPUT"
26- # else
27- # echo "Previous release tag found: $PREV_TAG"
1+ # Copyright 2021 Google LLC
2+ #
3+ # Licensed under the Apache License, Version 2.0 (the "License");
4+ # you may not use this file except in compliance with the License.
5+ # You may obtain a copy of the License at
6+ #
7+ # http://www.apache.org/licenses/LICENSE-2.0
8+ #
9+ # Unless required by applicable law or agreed to in writing, software
10+ # distributed under the License is distributed on an "AS IS" BASIS,
11+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+ # See the License for the specific language governing permissions and
13+ # limitations under the License.
14+
15+ name : Publish Casp CLI to PyPI
16+
17+ on :
18+ release :
19+ types : [published]
20+
21+ jobs :
22+ publish-pypi :
23+ name : Build and Publish CLI
24+ runs-on : ubuntu-latest
25+ permissions :
26+ contents : read
27+ steps :
28+ - uses : actions/checkout@v4
29+ with :
30+ fetch-depth : 0
31+
32+ - name : Check for changes in cli/casp
33+ id : check_changes
34+ run : |
35+ PREV_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || true)
36+
37+ if [ -z "$PREV_TAG" ]; then
38+ echo "No previous tag found (likely first release). Publishing..."
39+ echo "changed=true" >> "$GITHUB_OUTPUT"
40+ else
41+ echo "Previous release tag found: $PREV_TAG"
2842
29- # if git diff --quiet "$PREV_TAG" HEAD -- cli/casp; then
30- # echo "No changes detected in cli/casp."
31- # echo "changed=false" >> "$GITHUB_OUTPUT"
32- # else
33- # echo "Changes detected in cli/casp."
34- # echo "changed=true" >> "$GITHUB_OUTPUT"
35- # fi
36- # fi
37-
38- # - name: Set up Python
39- # if: steps.check_changes.outputs.changed == 'true'
40- # uses: actions/setup-python@v4
41- # with:
42- # python-version: '3.11'
43-
44- # - name: Install build dependencies
45- # if: steps.check_changes.outputs.changed == 'true'
46- # run: python -m pip install build --user
47-
48- # - name: Build package
49- # if: steps.check_changes.outputs.changed == 'true'
50- # working-directory: cli/casp
51- # run: python -m build
52-
53- # - name: Publish to PyPI
54- # if: steps.check_changes.outputs.changed == 'true'
55- # uses: pypa/gh-action-pypi-publish@release/v1
56- # with:
57- # password: ${{ secrets.PYPI_API_TOKEN }}
58- # packages_dir: cli/casp/dist/
59- # skip_existing: true
43+ if git diff --quiet "$PREV_TAG" HEAD -- cli/casp; then
44+ echo "No changes detected in cli/casp."
45+ echo "changed=false" >> "$GITHUB_OUTPUT"
46+ else
47+ echo "Changes detected in cli/casp."
48+ echo "changed=true" >> "$GITHUB_OUTPUT"
49+ fi
50+ fi
51+
52+ - name : Set up Python
53+ if : steps.check_changes.outputs.changed == 'true'
54+ uses : actions/setup-python@v4
55+ with :
56+ python-version : ' 3.11'
57+
58+ - name : Install build dependencies
59+ if : steps.check_changes.outputs.changed == 'true'
60+ run : python -m pip install build --user
61+
62+ - name : Set version to release tag
63+ if : steps.check_changes.outputs.changed == 'true'
64+ working-directory : cli/casp
65+ run : |
66+ # Get the tag name from the release event (e.g., v1.0.0)
67+ TAG_NAME=${{ github.event.release.tag_name }}
68+ # Strip the leading 'v' to get the version (e.g., 1.0.0)
69+ VERSION=${TAG_NAME#v}
70+
71+ echo "Updating version in pyproject.toml to $VERSION"
72+ sed -i "s/^version = \".*\"/version = \"$VERSION\"/" pyproject.toml
73+
74+ - name : Build package
75+ if : steps.check_changes.outputs.changed == 'true'
76+ working-directory : cli/casp
77+ run : python -m build
78+
79+ - name : Publish to PyPI
80+ if : steps.check_changes.outputs.changed == 'true'
81+ uses : pypa/gh-action-pypi-publish@release/v1
82+ with :
83+ password : ${{ secrets.CASP_PYPI_API_TOKEN }}
84+ packages_dir : cli/casp/dist/
85+ skip_existing : true
0 commit comments