Build and Release #42
This file contains 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: Build and Release | |
on: | |
# checkov:skip=CKV_GHA_7 | |
workflow_dispatch: | |
inputs: | |
type: | |
description: "Release type" | |
required: true | |
type: choice | |
options: | |
- "Stable" | |
- "Pre-release" | |
cf_type: | |
description: "CF Release Type" | |
required: true | |
type: choice | |
options: | |
- "Release" | |
- "Beta" | |
- "Alpha" | |
default: "Beta" | |
draft: | |
description: "Draft GitHub release (CF release will always be normal)" | |
type: boolean | |
default: true | |
generate_release_notes: | |
description: "Auto generate release notes" | |
type: boolean | |
default: true | |
required: false | |
skip_build: | |
description: "Skip build/test step" | |
type: boolean | |
default: false | |
run_id: | |
description: "Run ID to grab artifacts from if skipping build" | |
type: number | |
required: false | |
skip_github_release: | |
description: "Skip GitHub release" | |
type: boolean | |
default: false | |
required: false | |
skip_cf_release: | |
description: "Skip CurseForge release" | |
type: boolean | |
default: false | |
required: false | |
permissions: {} | |
jobs: | |
pre-build: | |
uses: ./.github/workflows/get_version_info.yml | |
build: | |
needs: pre-build | |
if: inputs.skip_build != true | |
permissions: | |
id-token: write | |
contents: read | |
packages: write | |
uses: ./.github/workflows/build_pr.yml | |
with: | |
target: build-all | |
secrets: inherit | |
release: | |
permissions: | |
contents: write | |
packages: read | |
statuses: write | |
needs: [build, pre-build] | |
runs-on: ubuntu-latest | |
if: success() || needs.build.result == 'skipped' | |
steps: | |
- name: Check Build or Skip | |
if: ${{ needs.build.result == 'failure' || needs.pre-build.result == 'failure'}} | |
run: exit 1 | |
shell: bash | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
fetch-tags: true | |
- name: Determine tag | |
id: tag | |
run: | | |
tag="${{needs.pre-build.outputs.version_tag}}" | |
echo "tag=$tag" >> "$GITHUB_OUTPUT" | |
shell: bash | |
- name: Determine name | |
id: name | |
run: | | |
if [[ "${{ github.event.inputs.cf_type }}" != "" ]]; then | |
# Get prefix first char capitalized | |
prefix=$(echo "${{ github.event.inputs.cf_type }}" | awk '{print toupper(substr($0, 1, 1)) tolower(substr($0, 2))}') | |
name="${prefix} ${{needs.pre-build.outputs.version}}" | |
else | |
name="${{needs.pre-build.outputs.version}}" | |
fi | |
echo "Release name will be $name" | |
echo "name=$name" >> "$GITHUB_OUTPUT" | |
shell: bash | |
- name: Download artifacts - Current Flow | |
if: ${{ inputs.skip_build == false }} | |
uses: actions/[email protected] | |
with: | |
path: artifacts | |
- name: Download artifacts - Previous Flow | |
if: ${{ inputs.skip_build == true}} | |
uses: actions/[email protected] | |
with: | |
path: artifacts | |
run-id: ${{ github.event.inputs.run_id }} | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
- name: Rename artifacts | |
id: artifacts | |
run: | | |
cd artifacts/build-zipzip | |
for file in ./*; do | |
if [[ $file == *.zip ]]; then | |
base=$(basename $file) | |
versioned_file="Monifactory-${{steps.name.outputs.name}}-$base" | |
mv "$file" "$versioned_file" | |
fi | |
done | |
wait | |
echo "Cleaning up - Removing non-zip files" | |
shopt -s extglob | |
rm -rf !(*.zip) | |
shell: bash | |
- name: Create body | |
id: body | |
run: | | |
ACTION_RUN_URL="https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}" | |
message="${{ github.event.inputs.type }} release ${{needs.pre-build.outputs.version}}. | |
The latest commit is ${{ needs.pre-build.outputs.current_commit }}. | |
Refer to the [action run]($ACTION_RUN_URL) that created this release." | |
echo "body<<EOF"$'\n'"$message"$'\n'EOF >> "$GITHUB_OUTPUT" | |
shell: bash | |
- name: Create GitHub Release | |
uses: ncipollo/[email protected] | |
id: release | |
if: ${{ inputs.skip_github_release == false }} | |
with: | |
artifacts: artifacts/build-zipzip/* | |
name: ${{ steps.name.outputs.name }} | |
tag: ${{ steps.tag.outputs.tag }} | |
generateReleaseNotes: ${{ inputs.generate_release_notes }} | |
prerelease: ${{ github.event.inputs.type == 'Pre-release' }} | |
draft: ${{ github.event.inputs.draft }} | |
body: ${{ steps.body.outputs.body }} | |
allowUpdates: true | |
updateOnlyUnreleased: true | |
removeArtifacts: true | |
commit: ${{ needs.pre-build.outputs.current_commit }} | |
- name: Echo Release URL | |
run: | | |
echo "Release URL: ${{ steps.release.outputs.html_url }}" | |
shell: bash | |
- name: Get server and client file paths | |
id: filepaths | |
run: | | |
server_file=$(ls artifacts/build-zipzip/*server*.zip) | |
client_file=$(ls artifacts/build-zipzip/*client*.zip) | |
echo "server_file=$server_file" >> "$GITHUB_OUTPUT" | |
echo "client_file=$client_file" >> "$GITHUB_OUTPUT" | |
shell: bash | |
- uses: henkelmax/[email protected] | |
if: ${{ inputs.skip_cf_release == false }} | |
with: | |
api-token: ${{ secrets.RELEASE_TOKEN }} | |
project-id: ${{vars.CF_PROJECT_ID}} | |
modpack-path: "${{steps.filepaths.outputs.client_file}}" | |
modpack-server-path: "${{steps.filepaths.outputs.server_file}}" | |
changelog: "For a detailed changelog, see the GitHub release: ${{ steps.release.outputs.html_url }}" | |
changelog-format: "text" | |
game-version: "1.20.1" | |
display-name: "Monifactory-${{steps.name.outputs.name}}" | |
server-display-name: "Monifactory-${{steps.name.outputs.name}} Server" | |
release-type: ${{ github.event.inputs.cf_type }} |