Skip to content

Commit 42cac83

Browse files
committed
ci: correctly release when previous workflow are successful
1 parent e9c387a commit 42cac83

2 files changed

Lines changed: 69 additions & 81 deletions

File tree

.github/workflows/main.yml

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,72 @@ jobs:
6767
with:
6868
python-version: ${{ needs.config.outputs.python-version }}
6969
- name: Run Tests
70-
run: poetry run pytest
70+
run: poetry run pytest
71+
72+
release:
73+
needs: [ config, setup, format, lint, type-check, test ]
74+
if: github.ref == 'refs/heads/main'
75+
runs-on: ubuntu-latest
76+
steps:
77+
- uses: actions/checkout@v4
78+
with:
79+
fetch-depth: 0
80+
- uses: ./.github/actions/setup-env
81+
with:
82+
python-version: ${{ needs.config.outputs.python-version }}
83+
84+
- name: Read version from pyproject.toml
85+
id: get_version
86+
run: |
87+
VERSION=$(poetry version --short)
88+
echo "VERSION=${VERSION}" >> $GITHUB_ENV
89+
90+
- name: Check if release exists
91+
run: |
92+
RELEASE_EXISTS=$(curl -s -o /dev/null -w "%{http_code}" https://api.github.com/repos/${{ github.repository }}/releases/tags/${{ env.VERSION }})
93+
if [ "$RELEASE_EXISTS" == "404" ]; then
94+
echo "CREATE_RELEASE=true" >> $GITHUB_ENV
95+
else
96+
echo "CREATE_RELEASE=false" >> $GITHUB_ENV
97+
98+
- name: Find Previous Release
99+
if: env.CREATE_RELEASE == 'true'
100+
run: |
101+
PREV_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
102+
if [ -n "$PREV_TAG" ]; then
103+
echo "PREV_TAG=${PREV_TAG}" >> $GITHUB_ENV
104+
fi
105+
106+
- name: Generate Compare URL
107+
if: env.CREATE_RELEASE == 'true'
108+
run: |
109+
if [ -n "${{ env.PREV_TAG }}" ]; then
110+
echo "URL=${{ github.server_url }}/${{ github.repository }}/compare/${{ env.PREV_TAG }}...${{ env.VERSION }}" >> $GITHUB_ENV
111+
else
112+
echo "URL=${{ github.server_url }}/${{ github.repository }}/releases/tag/${{ env.VERSION }}" >> $GITHUB_ENV
113+
fi
114+
115+
- name: Generate Changelog
116+
if: env.CREATE_RELEASE == 'true'
117+
run: |
118+
chmod +x .github/generate_changelog.sh
119+
source .github/generate_changelog.sh
120+
121+
echo "CHANGELOG<<EOF" >> $GITHUB_ENV
122+
if [ -n "${{ env.PREV_TAG }}" ]; then
123+
generate_categorized_changelog "${{ env.PREV_TAG }}" >> $GITHUB_ENV
124+
else
125+
generate_categorized_changelog >> $GITHUB_ENV
126+
fi
127+
echo "EOF" >> $GITHUB_ENV
128+
129+
- name: Create Release
130+
if: env.CREATE_RELEASE == 'true'
131+
uses: softprops/action-gh-release@v2
132+
with:
133+
tag_name: ${{ env.VERSION }}
134+
name: ${{ env.VERSION }}
135+
body: |
136+
${{ env.CHANGELOG }}
137+
138+
**Full Changelog**:

.github/workflows/release.yml

Lines changed: 0 additions & 80 deletions
This file was deleted.

0 commit comments

Comments
 (0)