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