1- name : Create Release
1+ name : Prepare Release & Publish Package
22
33on :
44 workflow_dispatch :
55 inputs :
6- is_prerelease :
7- description : ' Create a prerelease:'
8- type : boolean
6+ target_branch :
7+ description : " Branch or tag to release from"
8+ type : choice
9+ options : [ main, master, develop ]
10+ default : main
911 required : true
10- default : false
11- is_draft :
12- description : ' Set as a draft:'
13- type : boolean
12+ increment :
13+ description : " Version bump"
14+ type : choice
15+ options : [ major, minor, patch ]
16+ default : patch
1417 required : true
15- default : false
1618
1719permissions :
18- contents : write
19-
20- env :
21- ALLOW_PRERELEASE : ${{ startsWith(github.ref, 'refs/heads/develop') || startsWith(github.ref, 'refs/heads/hotfix/') }}
20+ contents : write
21+ pull-requests : write
22+ packages : write
2223
2324jobs :
24- create-release :
25+ validate_branch :
2526 runs-on : ubuntu-latest
2627
28+
29+ outputs :
30+ version_json_path : ${{ steps.locate_version.outputs.file }}
31+
2732 steps :
28- - name : Check For Valid Prerelease
29- if : ${{ ( env.ALLOW_PRERELEASE == 'true' && github.event.inputs.is_prerelease == 'false' ) || ( github.ref == 'refs/heads/main' && github.event.inputs.is_prerelease == 'true' ) }}
30- run : |
31- echo "Prereleases should not be triggered on the main branch, please use development or hotfix"
32- exit 1
33-
34- - name : Checkout Code
35- uses : actions/checkout@v4
36-
37- - name : Get Current Version
38- id : get_version
39- shell : pwsh
40- run : |
41- Import-Module ./solution-helper.psm1 -Force
42- $version = Get-Version
43- if ("${{ github.event.inputs.is_prerelease }}" -eq "true") {
44- $version_tag = "$version-develop.$(date +'%y%m%d%H%M%S')"
45- } else {
46- $version_tag = $version
47- }
48- echo "version_tag=$version_tag" | Out-File -FilePath $env:GITHUB_ENV -Append
49-
50- - name : Create Release
51- run : |
52- echo "🎁 Creating release ${{ env.version_tag }}"
53- gh release create ${{ env.version_tag }} \
54- --target ${{ github.ref_name }} \
55- --title ${{ env.version_tag }} \
56- --generate-notes \
57- $(if [[ "${{ github.event.inputs.is_draft }}" == "true" ]]; then echo "--draft"; fi) \
58- $(if [[ "${{ github.event.inputs.is_prerelease }}" == "true" ]]; then echo "--prerelease"; fi) \
59- $(if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then echo "--latest"; fi)
60- env :
61- GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
33+ - name : Checkout target branch
34+ uses : actions/checkout@v4
35+ with :
36+ fetch-depth : 1
37+ ref : ${{ inputs.target_branch }}
38+
39+ # Optional sanity check (keeps the job obvious when the ref is wrong)
40+ - name : Ensure target branch exists
41+ run : |
42+ if ! git rev-parse --verify --quiet "refs/heads/${{ inputs.target_branch }}"; then
43+ echo "::error::Ref '${{ inputs.target_branch }}' not found."
44+ exit 1
45+ fi
46+
47+ # Find version.json and emit its absolute path
48+ - name : Locate version.json
49+ id : locate_version
50+ shell : bash
51+ run : |
52+ # Search Git-tracked files first …
53+ REL_PATH=$(git ls-files --full-name '*version.json' | head -n1)
54+
55+ # … fall back to a filesystem search for untracked files (optional)
56+ if [[ -z "$REL_PATH" ]]; then
57+ REL_PATH=$(find . -type f -name version.json | head -n1 | sed 's|^\./||')
58+ fi
59+
60+ if [[ -z "$REL_PATH" ]]; then
61+ echo "::error::version.json not found on branch '${{ inputs.target_branch }}'."
62+ tree -L 2 -C || true
63+ exit 1
64+ fi
65+
66+ ABS_PATH="$GITHUB_WORKSPACE/$REL_PATH"
67+ echo "Found version.json at: $ABS_PATH"
68+
69+ # Pass the path to other jobs
70+ echo "file=$ABS_PATH" >> "$GITHUB_OUTPUT"
71+
72+ prepare :
73+ needs : validate_branch
74+ uses : Stillpoint-Software/shared-workflows/.github/workflows/nbgv_prepare_release.yml@main
75+ with :
76+ target_branch : ${{ inputs.target_branch }}
77+ increment : ${{ inputs.increment }}
78+ version_file_path : ${{ needs.validate_branch.outputs.version_json_path }}
79+ secrets : inherit
80+
81+ publish :
82+ needs : prepare
83+ uses : Stillpoint-Software/shared-workflows/.github/workflows/nbgv_dotnet_pack.yml@main
84+ with :
85+ checkout_ref : ${{ needs.prepare.outputs.release_branch }}
86+ build_configuration : ${{ inputs.target_branch == 'develop' && 'Develop' || 'Release' }}
87+ push_after_pack : true
88+ force_dev_prerelease : ${{ inputs.target_branch == 'develop' }}
89+ secrets :
90+ NUGET_API_KEY : ${{ secrets.NUGET_API_KEY }}
0 commit comments