diff --git a/.github/actions/meta/action.yml b/.github/actions/meta/action.yml new file mode 100644 index 0000000..2ad448c --- /dev/null +++ b/.github/actions/meta/action.yml @@ -0,0 +1,46 @@ +name: 'Read Metadata' +description: 'Reads metadata from modpack config and outputs it.' + +inputs: + working-directory: + description: 'Path to the modpack directory' + required: false + default: '.' + pack-file: + description: 'Path to the pack config file' + required: false + default: 'pack.toml' + +outputs: + mod-loader: + description: 'Detected mod loader' + value: ${{ steps.read.outputs.mod-loader }} + minecraft-version: + description: 'Detected minecraft version' + value: ${{ steps.read.outputs.minecraft-version }} + +runs: + using: 'composite' + steps: + # Checkout repository + - name: Checkout Repository + uses: actions/checkout@v4 + + # Read metadata in pack.toml and output to workflow + - name: Read Metadata + id: read + shell: bash + working-directory: ${{ inputs.working-directory }} + run: | + loaders=("fabric" "forge" "quilt" "neoforge", "rift") + for loader in "${loaders[@]}"; do + if [[ $(<"pack.toml") == *"$loader ="* ]]; then + MODPACK_MODLOADER="$loader" && break + fi + done + + [[ -z "$MODPACK_MODLOADER" ]] && { echo "::error file=pack.toml::No valid modpack loader found in pack.toml" && exit 1; } + + MODPACK_MINECRAFT_VERSION=$(grep -oP 'minecraft = "\K[^"]+' "pack.toml") + echo "mod-loader=$MODPACK_MODLOADER" >> $GITHUB_ENV + echo "minecraft-version=$MODPACK_MINECRAFT_VERSION" >> $GITHUB_ENV \ No newline at end of file diff --git a/.github/actions/release/action.yml b/.github/actions/release/action.yml new file mode 100644 index 0000000..bfc569b --- /dev/null +++ b/.github/actions/release/action.yml @@ -0,0 +1,91 @@ +name: 'Publish Release On External Platforms' +description: 'Publish a release to specific modding platforms.' + +inputs: + modrinth: + description: "Whether to upload to Modrinth" + required: true + curseforge: + description: "Whether to upload to CurseForge" + required: true + + working-directory: + description: 'Path to the modpack directory' + required: false + default: '.' + version: + description: 'Modpack version' + required: true + default: '1.0.0' + mod-loader: + description: "Detected mod loader" + required: true + default: 'fabric' + minecraft-version: + description: "Detected minecraft version" + required: true + changelog: + description: "The changelog as markdown text" + required: true + + MODRINTH_TOKEN: + required: false + description: "Token used for authenticating with Modrinth API" + MODRINTH_ID: + required: false + description: "Identifier used for authenticating with Modrinth API" + CURSEFORGE_TOKEN: + required: false + description: "Token used for authenticating with CurseForge API" + CURSEFORGE_ID: + required: false + description: "Identifier used for authenticating with CurseForge API" + +runs: + using: 'composite' + steps: + # Checkout repository + - name: Checkout Repository + uses: actions/checkout@v4 + + # Download release files + - name: Download Release + uses: robinraju/release-downloader@v1.11 + with: + fileName: "*" + tag: ${{ inputs.version }} + tarBall: false + zipBall: false + + # Create a markdown file of the release description + - name: Pipe Release Description to File + shell: bash + run: echo "${{ inputs.changelog }}" > CHANGELOG.release.md + + # Publish release to Modrinth + - name: Publish to Modrinth + if: inputs.modrinth == 'true' + uses: Kir-Antipov/mc-publish@v3.3 + with: + modrinth-id: ${{ inputs.MODRINTH_ID }} + modrinth-token: ${{ inputs.MODRINTH_TOKEN }} + loaders: ${{ inputs.mod-loader }} + game-versions: ${{ inputs.minecraft-version }} + files: "*.mrpack" + version: ${{ inputs.version }} + version-type: release + changelog-file: CHANGELOG.release.* + + # Publish release to CurseForge + - name: Publish to CurseForge + if: inputs.curseforge == 'true' + uses: Kir-Antipov/mc-publish@v3.3 + with: + curseforge-id: ${{ inputs.CURSEFORGE_ID }} + curseforge-token: ${{ inputs.CURSEFORGE_TOKEN }} + loaders: ${{ inputs.mod-loader }} + game-versions: ${{ inputs.minecraft-version }} + files: "*.zip" + version: ${{ inputs.version }} + version-type: release + changelog-file: CHANGELOG.release.* \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 4e07b9e..d1ca2d5 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -75,6 +75,13 @@ jobs: packwiz modrinth export --output Optim-${{ github.ref_name }}.mrpack working-directory: ./main + # Fetch modpack metadata from the modpack config + - name: Read Modpack Metadata + id: metadata + uses: ./.github/actions/meta + with: + working-directory: ./main + # Generate changelog - name: Generate changelog uses: ardalanamini/auto-changelog@v4 @@ -105,7 +112,7 @@ jobs: use-github-autolink: true # Create release - - name: Create Release Client + - name: Create Release Client (GitHub) uses: softprops/action-gh-release@v2 with: files: | @@ -117,3 +124,18 @@ jobs: prerelease: false generate_release_notes: false body: ${{ steps.changelog.outputs.changelog }} + + - name: Create Release Client (Modrinth) + uses: ./.github/actions/release + with: + working-directory: ./main + version: ${{ github.ref_name }} + mod-loader: ${{ steps.metadata.outputs.mod-loader }} + minecraft-version: ${{ steps.metadata.outputs.minecraft-version }} + modrinth: true + curseforge: true + MODRINTH_TOKEN: ${{ secrets.MODRINTH_TOKEN }} + MODRINTH_ID: ${{ secrets.MODRINTH_ID }} + CURSEFORGE_TOKEN: ${{ secrets.CURSEFORGE_TOKEN }} + CURSEFORGE_ID: ${{ secrets.CURSEFORGE_ID }} + changelog: ${{ steps.changelog.outputs.changelog }}