|
| 1 | +name: Release OpenVic-Simulation |
| 2 | +description: Setup, Build, and Release OpenVic-Simulation |
| 3 | + |
| 4 | +inputs: |
| 5 | + tag-name: |
| 6 | + description: 'Name to assign to the tag (default: github.ref)' |
| 7 | + default: ${{ github.ref }} |
| 8 | + type: string |
| 9 | + target-repo: |
| 10 | + description: Repository to publish this release to |
| 11 | + default: 'OpenVic-Simulation' |
| 12 | + type: string |
| 13 | + to-ref: |
| 14 | + description: 'Tag/Commit to publish this release to (default: github.ref)' |
| 15 | + default: ${{ github.ref }} |
| 16 | + type: string |
| 17 | + from-ref: |
| 18 | + description: Tag/Commit to source the release notes from |
| 19 | + type: string |
| 20 | + required: true |
| 21 | + from-tag: |
| 22 | + description: 'Tag name being sourced from (default: from-ref)' |
| 23 | + default: '' |
| 24 | + type: string |
| 25 | + nightly-release: |
| 26 | + description: Whether the release is a nightly build |
| 27 | + type: boolean |
| 28 | + default: false |
| 29 | + snapshot-release: |
| 30 | + description: Whether the release is a snapshot release |
| 31 | + type: boolean |
| 32 | + default: false |
| 33 | + latest: |
| 34 | + description: Latest |
| 35 | + type: boolean |
| 36 | + default: false |
| 37 | + prerelease: |
| 38 | + description: Pre-release |
| 39 | + type: boolean |
| 40 | + required: true |
| 41 | + src-token: |
| 42 | + description: Github token for source repository |
| 43 | + required: true |
| 44 | + target-token: |
| 45 | + description: Github token for target repository |
| 46 | + required: false |
| 47 | + default: '' |
| 48 | + |
| 49 | +runs: |
| 50 | + using: composite |
| 51 | + steps: |
| 52 | + - name: Copy src-token to env.TARGET_TOKEN |
| 53 | + if: inputs.target-repo == 'OpenVic-Simulation' |
| 54 | + shell: bash |
| 55 | + env: |
| 56 | + INPUTS_SRC_TOKEN: ${{ inputs.src-token }} |
| 57 | + run: echo "TARGET_TOKEN=$INPUTS_SRC_TOKEN" >> $GITHUB_ENV |
| 58 | + |
| 59 | + - name: Copy target-token to env.TARGET_TOKEN |
| 60 | + if: inputs.target-repo != 'OpenVic-Simulation' |
| 61 | + shell: bash |
| 62 | + env: |
| 63 | + INPUTS_TARGET_TOKEN: ${{ inputs.target-token }} |
| 64 | + run: | |
| 65 | + if [[ -z $INPUTS_TARGET_TOKEN ]]; then |
| 66 | + echo "::error file=.github/actions/openvic-sim-release/action.yml,line=66,endLine=66::target-repo was set to a different repository and the target-token was not set." |
| 67 | + exit 1 |
| 68 | + fi |
| 69 | + echo "TARGET_TOKEN=$INPUTS_TARGET_TOKEN" >> $GITHUB_ENV |
| 70 | +
|
| 71 | + - name: Set TO_TAG from to-ref |
| 72 | + if: inputs.tag-name == github.ref && !contains(inputs.to-ref, 'refs/tags') |
| 73 | + shell: bash |
| 74 | + env: |
| 75 | + INPUTS_TO_REF: ${{ inputs.to-ref }} |
| 76 | + run: echo "TO_TAG=$INPUTS_TO_REF" >> $GITHUB_ENV |
| 77 | + |
| 78 | + - name: Remove refs/tags from to-ref and set as TO_TAG |
| 79 | + if: inputs.tag-name == github.ref && contains(inputs.to-ref, 'refs/tags') |
| 80 | + shell: bash |
| 81 | + env: |
| 82 | + INPUTS_TO_REF: ${{ inputs.to-ref }} |
| 83 | + run: echo "TO_TAG=$(T='$INPUTS_TO_REF'; T=${T#"refs/tags/"}; echo $T)" >> $GITHUB_ENV |
| 84 | + |
| 85 | + - name: Set TO_TAG from tag-name |
| 86 | + if: inputs.tag-name != github.ref |
| 87 | + shell: bash |
| 88 | + env: |
| 89 | + INPUTS_TAG_NAME: ${{ inputs.tag-name }} |
| 90 | + run: echo "TO_TAG=$INPUTS_TAG_NAME" >> $GITHUB_ENV |
| 91 | + |
| 92 | + - name: Build Release Notes |
| 93 | + if: inputs.snapshot-release == 'false' && inputs.nightly-release == 'false' |
| 94 | + uses: mikepenz/release-changelog-builder-action@348e88fab4c37338b1e803ceb2d4a7a5db6c0833 # v6.2.2 |
| 95 | + env: |
| 96 | + GITHUB_TOKEN: ${{ inputs.src-token }} |
| 97 | + with: |
| 98 | + configuration: ".github/actions/openvic-sim-release/release-notes-configuration.json" |
| 99 | + toTag: ${{ contains(inputs.to-ref, 'refs/tags') && inputs.tag-name == github.ref && env.TO_TAG || inputs.to-ref }} |
| 100 | + fromTag: ${{ inputs.from-ref }} |
| 101 | + outputFile: release-notes.md |
| 102 | + |
| 103 | + - name: Build Snapshot Release Notes |
| 104 | + if: inputs.snapshot-release == 'true' && inputs.nightly-release == 'false' |
| 105 | + uses: mikepenz/release-changelog-builder-action@348e88fab4c37338b1e803ceb2d4a7a5db6c0833 # v6.2.2 |
| 106 | + env: |
| 107 | + GITHUB_TOKEN: ${{ inputs.src-token }} |
| 108 | + with: |
| 109 | + configuration: ".github/actions/openvic-sim-release/snapshot-release-notes-configuration.json" |
| 110 | + toTag: ${{ contains(inputs.to-ref, 'refs/tags') && inputs.tag-name == github.ref && env.TO_TAG || inputs.to-ref }} |
| 111 | + fromTag: ${{ inputs.from-ref }} |
| 112 | + outputFile: release-notes.md |
| 113 | + |
| 114 | + - name: Build Nightly Release Notes |
| 115 | + if: inputs.nightly-release == 'true' && inputs.snapshot-release == 'false' |
| 116 | + uses: mikepenz/release-changelog-builder-action@348e88fab4c37338b1e803ceb2d4a7a5db6c0833 # v6.2.2 |
| 117 | + env: |
| 118 | + GITHUB_TOKEN: ${{ inputs.src-token }} |
| 119 | + with: |
| 120 | + configuration: ".github/actions/openvic-sim-release/nightly-release-notes-configuration.json" |
| 121 | + toTag: ${{ contains(inputs.to-ref, 'refs/tags') && inputs.tag-name == github.ref && env.TO_TAG || inputs.to-ref }} |
| 122 | + fromTag: ${{ inputs.from-ref }} |
| 123 | + outputFile: release-notes.md |
| 124 | + |
| 125 | + - name: Create release tag and name and set release name in release-notes.md |
| 126 | + if: inputs.tag-name != github.ref |
| 127 | + shell: bash |
| 128 | + env: |
| 129 | + INPUTS_TAG_NAME: ${{ inputs.tag-name }} |
| 130 | + run: | |
| 131 | + # Sets major, minor, patch, prerelease_type, prerelease_version, year, month, day, dev, and hash values in bash environment |
| 132 | + declare $(awk ' |
| 133 | + split($0, sections, /[-+]?/) split(sections[1], version, /\./) split(sections[2], prerelease, /\./) { |
| 134 | + year="" |
| 135 | + month="" |
| 136 | + day="" |
| 137 | + prerelease_version="" |
| 138 | + dev="" |
| 139 | + if (prerelease[1] == "snapshot" && prerelease[2] == "dev") |
| 140 | + dev="dev" |
| 141 | + if (prerelease[1] == "nightly") { |
| 142 | + year=prerelease[2] |
| 143 | + month=prerelease[3] |
| 144 | + day=prerelease[4] |
| 145 | + } else { |
| 146 | + prerelease_version=prerelease[2] |
| 147 | + } |
| 148 | + } END { |
| 149 | + version_core=version[1]"."version[2] |
| 150 | + if (version[3] != "") { |
| 151 | + version_core=version_core"."version[3] |
| 152 | + } |
| 153 | +
|
| 154 | + prerelease_name=prerelease[1] |
| 155 | + if (prerelease[1] == "rc") { |
| 156 | + prerelease_name="Release Candidate" |
| 157 | + } |
| 158 | + sub(".", substr(toupper(prerelease_name), 1,1) , prerelease_name) |
| 159 | + if (dev != "") { |
| 160 | + prerelease_name=dev" "prerelease_name |
| 161 | + } |
| 162 | + sub(".", substr(toupper(prerelease_name), 1,1) , prerelease_name) |
| 163 | +
|
| 164 | + prerelease_date_or_version=prerelease_version |
| 165 | + if (prerelease[1] == "nightly") { |
| 166 | + prerelease_date_or_version=year"."month"."day |
| 167 | + } |
| 168 | +
|
| 169 | + dotted_dev="" |
| 170 | + if (dev == "dev") { |
| 171 | + dotted_dev=".dev" |
| 172 | + } |
| 173 | +
|
| 174 | + print "version_core="version_core, "prerelease_type="prerelease[1] dotted_dev, "prerelease_version="prerelease_version, "prerelease_name="prerelease_name, "prerelease_date_or_version="prerelease_date_or_version, "hash="sections[3] |
| 175 | + }' <<< "$INPUTS_TAG_NAME") |
| 176 | +
|
| 177 | + # Keep up to date with .github/actions/openvic-sim-release/nightly-release-notes-configuration.json |
| 178 | + sed -i "s/<<RELEASE_NAME_REPLACEMENT>>/$version_core $prerelease_name $prerelease_date_or_version/g" release-notes.md |
| 179 | + sed -i "s/<<FROM_TAG_NAME_REPLACEMENT>>/${{ inputs.from-tag || inputs.from-ref }}/g" release-notes.md |
| 180 | +
|
| 181 | + - name: Replace <<REPO>> in release-notes.md |
| 182 | + shell: bash |
| 183 | + run: sed -i "s/<<REPO>>/$(sed 's;\/;\\\/;g' <<< "${{ github.repository }}")/g" release-notes.md |
| 184 | + |
| 185 | + - name: Replace <<REPO_NAME>> in release-notes.md |
| 186 | + shell: bash |
| 187 | + run: sed -i "s/<<REPO_NAME>>/$(basename ${{ github.repository }})/g" release-notes.md |
| 188 | + |
| 189 | + - name: Capitalize everything in <<capitalize:>> in release-notes.md |
| 190 | + shell: bash |
| 191 | + run: sed -i 's/<<capitalize:\([^>]*\)*>>/\u\1/g' release-notes.md |
| 192 | + |
| 193 | + - name: Handle <<optional:>> in release-notes.md |
| 194 | + shell: bash |
| 195 | + run: | |
| 196 | + # Trim whitespace around of <<optional:contents>> |
| 197 | + # Add space to both sides of contents |
| 198 | + # Replace empty double space <<optional: >> tag (representing empty optional) with single space |
| 199 | + # Replace <<optional:contents>> tag with contents |
| 200 | + # strip <<trim-right: and >> |
| 201 | + sed -i 's/[ ]*<<optional:\([^>]*\)*>>[ ]*/<<optional: \1 >>/g; s/<<optional: >>/ /g; s/<<optional:\([^>]*\)*>>/\1/g' release-notes.md |
| 202 | +
|
| 203 | + - name: Retrieve RELEASE_NAME from release-notes.md |
| 204 | + shell: bash |
| 205 | + run: echo "RELEASE_NAME=$(grep -oP '^##\s*Release Notes for\s+\K.*' release-notes.md | head -n1)" >> $GITHUB_ENV |
| 206 | + |
| 207 | + - name: Make library directory |
| 208 | + shell: sh |
| 209 | + run: mkdir "${{ github.workspace }}/library/" |
| 210 | + |
| 211 | + - name: Download library assets |
| 212 | + uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 |
| 213 | + with: |
| 214 | + path: "${{ github.workspace }}/library" |
| 215 | + pattern: ${{ github.event.repository.name }}-*-library |
| 216 | + merge-multiple: true |
| 217 | + |
| 218 | + - name: Download executable assets |
| 219 | + uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 |
| 220 | + with: |
| 221 | + pattern: ${{ github.event.repository.name }}-*-executable |
| 222 | + merge-multiple: true |
| 223 | + |
| 224 | + - name: Zip library assets |
| 225 | + uses: thedoctor0/zip-release@b57d897cb5d60cb78b51a507f63fa184cfe35554 # v0.7.6 |
| 226 | + with: |
| 227 | + type: "zip" |
| 228 | + filename: libopenvic-simulation.zip |
| 229 | + path: library |
| 230 | + |
| 231 | + - name: Create and upload asset |
| 232 | + uses: ncipollo/release-action@339a81892b84b4eeb0f6e744e4574d79d0d9b8dd # v1.21.0 |
| 233 | + with: |
| 234 | + allowUpdates: true |
| 235 | + artifacts: "libopenvic-simulation.zip,openvic-simulation.headless.**" |
| 236 | + omitNameDuringUpdate: true |
| 237 | + omitBodyDuringUpdate: true |
| 238 | + name: "${{ env.RELEASE_NAME || '' }}" |
| 239 | + tag: "${{ env.TO_TAG || '' }}" |
| 240 | + commit: "${{ format('{0}/{1}', github.repository_owner, inputs.target-repo) == github.repository && !contains(inputs.to-ref, '.') && inputs.to-ref || '' }}" |
| 241 | + bodyFile: "release-notes.md" |
| 242 | + makeLatest: ${{ inputs.latest }} |
| 243 | + prerelease: ${{ inputs.prerelease }} |
| 244 | + draft: ${{ inputs.snapshot-release == 'false' && inputs.nightly-release == 'false' }} |
| 245 | + repo: "${{ inputs.target-repo }}" |
| 246 | + token: ${{ env.TARGET_TOKEN }} |
0 commit comments