[AUTO] Update version to 0.1.24.126-develop #4
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
| name: Develop - build image and push | |
| # This workflow builds and pushes a Docker image to GitHub Container Registry. | |
| # It is triggered on pushes and pull requests to the "develop" branch, and can also be triggered manually. | |
| # The image is tagged with "develop" and a version string based on the workflow run number. | |
| # For pull requests, the Docker image is uploaded as an artifact instead of being pushed to the registry. | |
| # Old Docker images with the "develop" version prefix are cleaned up to save space. | |
| # The workflow uses the GITHUB_TOKEN secret for authentication with GitHub Container Registry. | |
| on: | |
| push: | |
| branches: [ "develop" ] | |
| pull_request: | |
| branches: [ "develop" ] | |
| workflow_dispatch: # allows manual triggering of the workflow | |
| env: | |
| VERSION_PREFIX: 0.1.24. | |
| VERSION_SUFFIX: -develop | |
| jobs: | |
| publish_image: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Pull latest changes | |
| run: git pull origin develop --rebase | |
| - name: Set version string | |
| run: echo "VERSION=${{ env.VERSION_PREFIX }}${{ github.run_number }}${{env.VERSION_SUFFIX}}" >> $GITHUB_ENV | |
| - name: Write version to file | |
| run: echo "__version__ = '${{ env.VERSION }}'" > src/version.py | |
| - name: Commit version file and push changes | |
| if: github.event_name == 'push' | |
| uses: devops-infra/action-commit-push@master | |
| with: | |
| github_token: ${{ secrets.GITHUB_TOKEN }} | |
| commit_prefix: "[AUTO] " | |
| commit_message: "Update version to ${{ env.VERSION }}" | |
| - name: Convert repository owner to lowercase | |
| run: echo "owner=$(echo '${{ github.repository_owner }}' | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV | |
| - name: Build image | |
| run: docker build -t ghcr.io/${{ env.owner }}/eos_connect:develop . | |
| # Only upload the image artifact for pull_request events | |
| - name: Upload Docker image as artifact | |
| if: github.event_name == 'pull_request' | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: eos_connect_image-${{ env.VERSION }} | |
| path: eos_connect_${{ env.VERSION }}.tar.gz | |
| # Only run tagging and pushing tasks for "push" events | |
| - name: Log in to GitHub Container Registry | |
| if: github.event_name == 'push' | |
| run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin | |
| - name: Tag image with develop version | |
| if: github.event_name == 'push' | |
| run: docker tag ghcr.io/${{ env.owner }}/eos_connect:develop ghcr.io/${{ env.owner }}/eos_connect:${{ env.VERSION }} | |
| - name: Push Docker image to GitHub Container Registry | |
| if: github.event_name == 'push' | |
| run: | | |
| docker push ghcr.io/${{ env.owner }}/eos_connect:develop | |
| docker push ghcr.io/${{ env.owner }}/eos_connect:${{ env.VERSION }} | |
| cleanup_old_develops: | |
| needs: publish_image | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Cleanup old Docker images | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| echo "Cleaning up old Docker images..." | |
| ghcr_images=$(gh api -H "Authorization: token $GH_TOKEN" /user/packages/container/eos_connect/versions | jq -r '.[] | select(.metadata.container.tags[] | endswith("${{ env.VERSION_SUFFIX }}")) | .id' | tail -n +4) | |
| for image_id in $ghcr_images; do | |
| gh api -X DELETE -H "Authorization: token $GH_TOKEN" /user/packages/container/eos_connect/versions/$image_id | |
| done |