|
| 1 | +name: 🧬 Version |
| 2 | +run-name: Get version with GitVersion |
| 3 | + |
| 4 | +on: |
| 5 | + workflow_call: |
| 6 | + outputs: |
| 7 | + semVer: |
| 8 | + description: 'GitVersion semantic version' |
| 9 | + value: ${{ jobs.version.outputs.majorMinorBuild }} |
| 10 | + nuGetVersion: |
| 11 | + description: 'GitVersion suffix for NuGet package' |
| 12 | + value: ${{ jobs.version.outputs.nuGetVersion }} |
| 13 | + majorMinorBuild: |
| 14 | + description: 'GitVersion major.minor.build version' |
| 15 | + value: ${{ jobs.version.outputs.majorMinorBuild }} |
| 16 | + projectName: |
| 17 | + description: 'Git repository project name' |
| 18 | + value: ${{ jobs.version.outputs.projectName }} |
| 19 | + projectFiles: |
| 20 | + description: 'Git repository project files' |
| 21 | + value: ${{ jobs.version.outputs.projectFiles }} |
| 22 | + |
| 23 | +jobs: |
| 24 | + version: |
| 25 | + name: Version |
| 26 | + runs-on: 'ubuntu-latest' |
| 27 | + |
| 28 | + outputs: # alternative usage: $GitVersion_<outputName> |
| 29 | + semVer: ${{ steps.gitversion.outputs.semVer }} |
| 30 | + nuGetVersion: ${{ steps.gitversion.outputs.nuGetVersion }} |
| 31 | + majorMinorPatch: ${{ steps.gitversion.outputs.majorMinorPatch }} |
| 32 | + projectName: ${{ steps.github_repository.outputs.basename }} |
| 33 | + projectFiles: ${{ steps.github_repository.outputs.projects }} |
| 34 | + |
| 35 | + steps: |
| 36 | + # https://github.com/actions/checkout#fetch-all-history-for-all-tags-and-branches |
| 37 | + - name: Fetch all tags and branches for GitVersion |
| 38 | + uses: actions/checkout@v4 |
| 39 | + with: |
| 40 | + fetch-depth: 0 |
| 41 | + |
| 42 | + - name: Get Git repository project name |
| 43 | + id: github_repository |
| 44 | + run: echo "::set-output name=basename::$(basename '${{ github.repository }}')" |
| 45 | + |
| 46 | + - name: List all project files in the directory |
| 47 | + shell: bash |
| 48 | + run: | |
| 49 | + shopt -s globstar |
| 50 | + projects="" |
| 51 | + for project in ./**/*.csproj; do |
| 52 | + echo "$project" |
| 53 | + projects+="::$project" |
| 54 | + done |
| 55 | +
|
| 56 | + # https://github.com/GitTools/actions/blob/main/docs/examples/github/gitversion/setup/usage-examples.md#example-1 |
| 57 | + - name: Set up GitVersion |
| 58 | + uses: gittools/actions/gitversion/setup@v0 |
| 59 | + with: |
| 60 | + versionSpec: '5.x' |
| 61 | + |
| 62 | + # https://github.com/GitTools/actions/blob/main/docs/examples/github/gitversion/execute/usage-examples.md#example-5 |
| 63 | + - name: Use GitVersion to determine version |
| 64 | + id: gitversion # e.g. steps.gitversion.outputs.<outputName> |
| 65 | + uses: gittools/actions/gitversion/execute@v0 |
| 66 | + |
| 67 | + # For a list of all GitVersion Version Variables, see https://gitversion.net/docs/reference/variables |
| 68 | + - run: | |
| 69 | + echo "Save the GitVersion outputs to a file." |
| 70 | + echo "${{ steps.gitversion.outputs }}" > version.txt |
| 71 | +
|
| 72 | + # pwsh> dotnet-gitversion | ConvertFrom-Json |
| 73 | + - if: contains(steps.gitversion.outputs.branchName, 'main') |
| 74 | + run: | |
| 75 | + echo "Generate release notes from the Git commit log." |
| 76 | + last_tag=$(git describe --abbrev=0 --tags) |
| 77 | + echo '## ${{ env.title }} changes up to $last_tag' > release-notes.txt |
| 78 | + git log --pretty=format:"- %s" $last_tag..HEAD >> release-notes.txt |
| 79 | + env: |
| 80 | + title: '${{ steps.github_repository.outputs.basename }} version ${{ steps.gitversion.outputs.preReleaseLabel }}' |
| 81 | + |
| 82 | + # https://github.com/actions/upload-artifact |
| 83 | + - name: Upload version artifacts |
| 84 | + uses: actions/upload-artifact@v3 |
| 85 | + with: |
| 86 | + name: ${{ inputs.sourceFolder }} |
| 87 | + path: | |
| 88 | + version.txt |
| 89 | + release-notes.txt |
| 90 | + ${{ inputs.sourceFolder }} |
| 91 | + retention-days: 1 |
| 92 | + if-no-files-found: error # or 'ignore', defaults to `warn` |
| 93 | + |
| 94 | + # https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#adding-a-job-summary |
| 95 | + - name: Markdown workflow job summary |
| 96 | + run: | |
| 97 | + echo '### ${{ env.WorkflowName }} build summary' >> $GITHUB_STEP_SUMMARY |
| 98 | + echo "${{ github.repository }} ${{ github.ref }}" >> $GITHUB_STEP_SUMMARY |
| 99 | + echo 'Label: ${{ steps.gitversion.outputs.preReleaseLabel }}' >> $GITHUB_STEP_SUMMARY |
| 100 | + echo 'Version: ${{ steps.gitversion.outputs.fullSemVer }}' >> $GITHUB_STEP_SUMMARY |
| 101 | + echo 'Commit Date: ${{ steps.gitversion.outputs.commitDate }}' >> $GITHUB_STEP_SUMMARY |
| 102 | + env: |
| 103 | + WorkflowName: '${{ steps.github_repository.outputs.basename }} version ${{ steps.gitversion.outputs.semVer }}' |
0 commit comments