-
Notifications
You must be signed in to change notification settings - Fork 0
rename workflow for better understanding #22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Baptiste-Ferrand
merged 1 commit into
develop
from
implementation/tag-release-changelog-package
Aug 6, 2025
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,234 @@ | ||
| name: Version, Tag, Release & Package | ||
|
|
||
| on: | ||
| pull_request: | ||
| types: [closed] | ||
| branches: | ||
| - main | ||
| - develop | ||
|
|
||
| jobs: | ||
| versioning-and-release: | ||
| if: github.event.pull_request.merged == true | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| contents: write | ||
| packages: write | ||
| outputs: | ||
| version: ${{ steps.version.outputs.version }} | ||
| full_tag: ${{ steps.version.outputs.full_tag }} | ||
| is_latest: ${{ steps.version.outputs.is_latest }} | ||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| fetch-depth: 0 | ||
| token: ${{ secrets.GITHUB_TOKEN }} | ||
|
|
||
| - name: Install toml | ||
| run: | | ||
| python -m pip install toml | ||
|
|
||
| - name: Get current version from pyproject.toml | ||
| id: get_version | ||
| run: | | ||
| VERSION=$(python -c "import toml; print(toml.load('pyproject.toml')['project']['version'])") | ||
| echo "CURRENT_VERSION=${VERSION}" >> $GITHUB_ENV | ||
|
|
||
| - name: Increment version based on source branch | ||
| id: increment_version | ||
| run: | | ||
| CURRENT_VERSION=${{ env.CURRENT_VERSION }} | ||
| BRANCH_NAME="${{ github.event.pull_request.head.ref }}" | ||
| TARGET_BRANCH="${{ github.base_ref }}" | ||
|
|
||
| CLEAN_VERSION=$(echo $CURRENT_VERSION | sed 's/-pre-prod//') | ||
|
|
||
| case $BRANCH_NAME in | ||
| feat/*|feature/*) | ||
| NEW_VERSION=$(echo $CLEAN_VERSION | awk -F. -v OFS=. '{$2++; $3=0; print $0}') | ||
| ;; | ||
| fix/*|hotfix/*) | ||
| NEW_VERSION=$(echo $CLEAN_VERSION | awk -F. -v OFS=. '{$3++; print $0}') | ||
| ;; | ||
| *breaking*|*major*) | ||
| NEW_VERSION=$(echo $CLEAN_VERSION | awk -F. -v OFS=. '{$1++; $2=0; $3=0; print $0}') | ||
| ;; | ||
| *) | ||
| NEW_VERSION=$CLEAN_VERSION | ||
| ;; | ||
| esac | ||
|
|
||
| if [[ "$TARGET_BRANCH" == "develop" ]]; then | ||
| FULL_VERSION="${NEW_VERSION}-pre-prod" | ||
| IS_LATEST="false" | ||
| elif [[ "$TARGET_BRANCH" == "main" ]]; then | ||
| FULL_VERSION="${NEW_VERSION}" | ||
| IS_LATEST="true" | ||
| fi | ||
|
|
||
| echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_ENV | ||
| echo "FULL_VERSION=$FULL_VERSION" >> $GITHUB_ENV | ||
| echo "IS_LATEST=$IS_LATEST" >> $GITHUB_ENV | ||
|
|
||
| - name: Extract changelog from PR description | ||
| id: extract_changelog | ||
| run: | | ||
| PR_BODY='${{ github.event.pull_request.body }}' | ||
|
|
||
| if echo "$PR_BODY" | grep -q "#changelog"; then | ||
| CHANGELOG=$(echo "$PR_BODY" | sed -n '/#changelog/,$p' | sed '1d' | sed '/^[[:space:]]*$/d') | ||
| else | ||
| CHANGELOG="- Update to version ${{ env.FULL_VERSION }}" | ||
| fi | ||
|
|
||
| if [ -z "$CHANGELOG" ]; then | ||
| CHANGELOG="- Update to version ${{ env.FULL_VERSION }}" | ||
| fi | ||
|
|
||
| { | ||
| echo 'CHANGELOG<<EOF' | ||
| echo "$CHANGELOG" | ||
| echo 'EOF' | ||
| } >> $GITHUB_ENV | ||
|
|
||
| - name: Update version in pyproject.toml | ||
| id: version | ||
| run: | | ||
| python -c "import toml; data = toml.load('pyproject.toml'); data['project']['version'] = '${{ env.FULL_VERSION }}'; toml.dump(data, open('pyproject.toml', 'w'))" | ||
|
Baptiste-Ferrand marked this conversation as resolved.
|
||
| echo "version=${{ env.NEW_VERSION }}" >> $GITHUB_OUTPUT | ||
| echo "full_tag=${{ env.FULL_VERSION }}" >> $GITHUB_OUTPUT | ||
| echo "is_latest=${{ env.IS_LATEST }}" >> $GITHUB_OUTPUT | ||
|
|
||
| - name: Commit and push updated pyproject.toml | ||
| run: | | ||
| git config --global user.name "GitHub Actions" | ||
| git config --global user.email "actions@github.com" | ||
|
|
||
| git add pyproject.toml | ||
| git commit -m "Update version to ${{ env.FULL_VERSION }}" | ||
| git push origin ${{ github.ref_name }} | ||
|
Baptiste-Ferrand marked this conversation as resolved.
|
||
|
|
||
| - name: Remove old latest tag | ||
| if: env.IS_LATEST == 'true' | ||
| run: | | ||
| if git tag -l | grep -q "^latest$"; then | ||
| git tag -d latest || true | ||
| git push origin :refs/tags/latest || true | ||
| fi | ||
|
|
||
| - name: Create Git tags | ||
| run: | | ||
| git config --global user.name "GitHub Actions" | ||
| git config --global user.email "actions@github.com" | ||
|
|
||
| git tag ${{ env.FULL_VERSION }} | ||
| git push origin ${{ env.FULL_VERSION }} | ||
|
|
||
| if [[ "${{ env.IS_LATEST }}" == "true" ]]; then | ||
| git tag latest | ||
| git push origin latest | ||
| fi | ||
|
|
||
| - name: Create GitHub Release | ||
| uses: softprops/action-gh-release@v2 | ||
| with: | ||
| tag_name: ${{ env.FULL_VERSION }} | ||
| name: "Release ${{ env.FULL_VERSION }}" | ||
| body: | | ||
| ## 📋 Changelog | ||
|
|
||
| ${{ env.CHANGELOG }} | ||
|
|
||
| ## 🏷️ Tags | ||
| - **Version**: `${{ env.FULL_VERSION }}`${{ env.IS_LATEST == 'true' && format('{0}- **Latest**: `latest`', ' | ||
| ') || '' }} | ||
|
|
||
| ## 📦 Docker Package | ||
|
|
||
| ```bash | ||
| # Pull specific version | ||
| docker pull ghcr.io/track-train/api:${{ env.FULL_VERSION }} | ||
| ${{ env.IS_LATEST == 'true' && format('{0}# Pull latest stable{0}docker pull ghcr.io/track-train/api:latest', ' | ||
| ') || '' }} | ||
| ``` | ||
|
|
||
| ## ℹ️ Information | ||
|
|
||
| - **Source branch**: `${{ github.event.pull_request.head.ref }}` | ||
| - **Target branch**: `${{ github.base_ref }}` | ||
| - **Release type**: ${{ env.IS_LATEST == 'true' && '**Stable** 🎯' || '**Pre-production** 🧪' }} | ||
| - **PR author**: @${{ github.event.pull_request.user.login }} | ||
| prerelease: ${{ env.IS_LATEST != 'true' }} | ||
| make_latest: ${{ env.IS_LATEST == 'true' }} | ||
| env: | ||
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
|
||
| build-and-deploy-image: | ||
| needs: versioning-and-release | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| contents: read | ||
| packages: write | ||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| ref: ${{ github.ref_name }} | ||
|
|
||
| - name: Login to GitHub Container Registry | ||
| uses: docker/login-action@v3 | ||
| with: | ||
| registry: ghcr.io | ||
| username: ${{ github.actor }} | ||
| password: ${{ secrets.GITHUB_TOKEN }} | ||
|
|
||
| - name: Set up Docker Buildx | ||
| uses: docker/setup-buildx-action@v3 | ||
|
|
||
| - name: Prepare Docker tags | ||
| id: prepare_tags | ||
| run: | | ||
| TAGS="ghcr.io/track-train/api:${{ needs.versioning-and-release.outputs.full_tag }}" | ||
|
|
||
| if [[ "${{ needs.versioning-and-release.outputs.is_latest }}" == "true" ]]; then | ||
| TAGS="${TAGS},ghcr.io/track-train/api:latest" | ||
| fi | ||
|
|
||
| echo "DOCKER_TAGS=${TAGS}" >> $GITHUB_ENV | ||
|
|
||
| - name: Build and push Docker image | ||
| uses: docker/build-push-action@v5 | ||
|
Baptiste-Ferrand marked this conversation as resolved.
|
||
| with: | ||
| context: . | ||
| push: true | ||
| platforms: linux/amd64,linux/arm64/v8 | ||
| tags: ${{ env.DOCKER_TAGS }} | ||
| labels: | | ||
| org.opencontainers.image.title=Track&Train API | ||
| org.opencontainers.image.description=API for Track&Train application | ||
| org.opencontainers.image.version=${{ needs.versioning-and-release.outputs.full_tag }} | ||
| org.opencontainers.image.revision=${{ github.sha }} | ||
| org.opencontainers.image.created=${{ github.event.head_commit.timestamp }} | ||
| org.opencontainers.image.source=${{ github.event.repository.clone_url }} | ||
|
|
||
| - name: Deployment summary | ||
| run: | | ||
| echo "## 🎉 Deployment successful!" >> $GITHUB_STEP_SUMMARY | ||
| echo "" >> $GITHUB_STEP_SUMMARY | ||
| echo "### 📦 Package created" >> $GITHUB_STEP_SUMMARY | ||
| echo "- **Version**: \`${{ needs.versioning-and-release.outputs.full_tag }}\`" >> $GITHUB_STEP_SUMMARY | ||
| if [[ "${{ needs.versioning-and-release.outputs.is_latest }}" == "true" ]]; then | ||
| echo "- **Latest**: \`latest\`" >> $GITHUB_STEP_SUMMARY | ||
| fi | ||
| echo "" >> $GITHUB_STEP_SUMMARY | ||
| echo "### 🐳 Docker commands" >> $GITHUB_STEP_SUMMARY | ||
| echo "\`\`\`bash" >> $GITHUB_STEP_SUMMARY | ||
| echo "docker pull ghcr.io/track-train/api:${{ needs.versioning-and-release.outputs.full_tag }}" >> $GITHUB_STEP_SUMMARY | ||
| if [[ "${{ needs.versioning-and-release.outputs.is_latest }}" == "true" ]]; then | ||
| echo "docker pull ghcr.io/track-train/api:latest" >> $GITHUB_STEP_SUMMARY | ||
| fi | ||
| echo "\`\`\`" >> $GITHUB_STEP_SUMMARY | ||
| echo "" >> $GITHUB_STEP_SUMMARY | ||
| echo "### 📋 pyproject.toml" >> $GITHUB_STEP_SUMMARY | ||
| echo "- Version in pyproject.toml updated automatically" >> $GITHUB_STEP_SUMMARY | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.