suggestion by ChatGPT #18
Workflow file for this run
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: Version & Docker | |
| on: | |
| pull_request: | |
| branches: [main] | |
| types: [closed] | |
| permissions: | |
| contents: read | |
| env: | |
| GIT_USER_NAME: GitHub Pipeline | |
| GIT_USER_EMAIL: [email protected] | |
| IMAGE_NAME: zalf/fairagro_advanced_middleware_api | |
| jobs: | |
| version: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| outputs: | |
| SemVer: ${{ steps.gitversion.outputs.SemVer }} | |
| Major: ${{ steps.gitversion.outputs.Major }} | |
| Minor: ${{ steps.gitversion.outputs.Minor }} | |
| Patch: ${{ steps.gitversion.outputs.Patch }} | |
| steps: | |
| - name: Checkout repo | |
| uses: actions/checkout@v5 | |
| with: | |
| ref: ${{ github.ref }} | |
| fetch-depth: 0 | |
| # Prüfen des Labels für Version Bump | |
| - name: Determine Version Bump | |
| id: version-bump | |
| uses: actions/github-script@v7 | |
| with: | |
| github-token: ${{ secrets.GITHUB_TOKEN }} | |
| script: | | |
| const allowedLabels = ["major version","minor version","patch version"]; | |
| const pr = context.payload.pull_request; | |
| const labels = pr.labels.map(l => l.name); | |
| console.log("Labels on PR:", labels); | |
| const matching = labels.filter(l => allowedLabels.includes(l)); | |
| console.log("Matching labels:", matching); | |
| const result = matching[0].replace(" version",""); | |
| console.log("Determined version bump:", result); | |
| core.setOutput("bump", result); | |
| # GitVersion für main Merge | |
| - name: Install GitVersion | |
| uses: gittools/actions/gitversion/setup@v4 | |
| with: | |
| versionSpec: 6.x | |
| - name: Execute GitVersion | |
| id: gitversion | |
| uses: gittools/actions/gitversion/execute@v4 | |
| with: | |
| configFilePath: GitVersion.yml | |
| overrideConfig: | | |
| increment=${{ steps.version-bump.outputs.bump }} | |
| - name: Show calculated version | |
| run: | | |
| echo "Calculated Version: ${{ steps.gitversion.outputs.SemVer }}" | |
| - name: Show computed feature version | |
| run: | | |
| echo "FullSemVer: ${{ steps.gitversion.outputs.FullSemVer }}" | |
| echo "SemVer: ${{ steps.gitversion.outputs.SemVer }}" | |
| echo "PreRelease: ${{ steps.gitversion.outputs.PreReleaseTag }}" | |
| - name: Create git tag | |
| run: | | |
| VERSION="${{ steps.gitversion.outputs.SemVer }}" | |
| git config user.name "${{ env.GIT_USER_NAME }}" | |
| git config user.email "{{ env.GIT_USER_EMAIL }}" | |
| git tag -a "v${VERSION}" -m "release $VERSION" | |
| git push origin "v${VERSION}" | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| docker-build-main: | |
| runs-on: ubuntu-latest | |
| needs: version | |
| steps: | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Docker metadata | |
| id: metadata | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: ${{ env.IMAGE_NAME }} | |
| tags: | | |
| type=semver,pattern={{version}},value=${{ needs.version.outputs.SemVer }} | |
| type=raw,value=${{ needs.version.outputs.Major }}.${{ needs.version.outputs.Minor }} | |
| type=raw,value=${{ needs.version.outputs.Major }} | |
| # Secrets are managed within the github GUI | |
| - name: Log in to Docker Hub | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ secrets.DOCKERHUB_USER }} | |
| password: ${{ secrets.DOCKERHUB_TOKEN }} | |
| - name: Build & Push Docker Image | |
| uses: docker/build-push-action@v6 | |
| with: | |
| push: true | |
| tags: ${{ steps.metadata.outputs.tags }} | |
| labels: ${{ steps.metadata.outputs.labels }} | |
| create-release: | |
| runs-on: ubuntu-latest | |
| needs: version | |
| permissions: | |
| contents: write | |
| steps: | |
| - name: Create GitHub Release | |
| uses: ncipollo/release-action@v1 | |
| with: | |
| tag: v${{ needs.version.outputs.SemVer }} | |
| name: "Release v${{ needs.version.outputs.SemVer }}" | |
| body: | | |
| Docker image: `${{ env.IMAGE_NAME }}:v${{ needs.version.outputs.SemVer }}` | |
| draft: false | |
| prerelease: false |