|
| 1 | +# This workflow must be manually triggered. It accepts a version and a release type. |
| 2 | +# First it sets the version in gradle.properties to the new version and pushes it. |
| 3 | +# Then it generates a log, based on commits. |
| 4 | +# After that builds a jar and uploads it to curseforge/modrinth/GitHub releases |
| 5 | + |
| 6 | +name: Build and Publish mod |
| 7 | + |
| 8 | +on: |
| 9 | + workflow_dispatch: |
| 10 | + inputs: |
| 11 | + version: |
| 12 | + description: 'Mod version' |
| 13 | + required: true |
| 14 | + release-type: |
| 15 | + description: 'Release type' |
| 16 | + type: choice |
| 17 | + default: 'beta' |
| 18 | + options: |
| 19 | + - 'release' |
| 20 | + - 'beta' |
| 21 | + - 'alpha' |
| 22 | + publish-cf-mr: |
| 23 | + description: Publish to CF / MR |
| 24 | + default: true |
| 25 | + type: boolean |
| 26 | + publish-gh: |
| 27 | + description: Publish to Github |
| 28 | + default: true |
| 29 | + type: boolean |
| 30 | + publish-maven: |
| 31 | + description: Publish to maven |
| 32 | + default: true |
| 33 | + type: boolean |
| 34 | + overwrite: |
| 35 | + description: 'Overwrite current tag (if exists)' |
| 36 | + default: false |
| 37 | + required: true |
| 38 | + type: boolean |
| 39 | + |
| 40 | +jobs: |
| 41 | + build: |
| 42 | + runs-on: ubuntu-latest |
| 43 | + steps: |
| 44 | + - name: Checkout Repository |
| 45 | + uses: actions/checkout@v3 |
| 46 | + with: |
| 47 | + token: ${{ secrets.PAT }} |
| 48 | + |
| 49 | + - name: Read current mod version |
| 50 | + id: read_version |
| 51 | + run: | |
| 52 | + mod_version=$(grep "mod_version" gradle.properties | cut -d'=' -f2 | tr -d '[:space:]') |
| 53 | + if [ "$mod_version" == "${{inputs.version}}" ]; then |
| 54 | + echo "UPDATED=true" >> $GITHUB_ENV |
| 55 | + else |
| 56 | + echo "UPDATED=false" >> $GITHUB_ENV |
| 57 | + fi |
| 58 | +
|
| 59 | + # Abort if a tag already exists and the mod is updated to that version and overwriting is not allowed |
| 60 | + # If the tag does not exist force publish to gh if publishing to cf/mr (for changelog) |
| 61 | + - name: Check if tag already exists |
| 62 | + run: | |
| 63 | + if git rev-parse --verify --quiet "v${{ github.event.inputs.version }}"; then |
| 64 | + if [ "${{ inputs.publish-gh }}" == "true" ] && [ "$UPDATED" == "true" ] && [ "${{ inputs.overwrite }}" == "false" ]; then |
| 65 | + echo "Version tag ${{ github.event.inputs.version }} already exists and the mod is updated to that version and overwriting is forbidden." |
| 66 | + echo "Aborting workflow!" |
| 67 | + exit 1 |
| 68 | + fi |
| 69 | + echo "publish-gh=${{ inputs.publish-gh }}" >> $GITHUB_ENV |
| 70 | + else |
| 71 | + if [ "${{ inputs.publish-cf-mr }}" == "true" ]; then |
| 72 | + echo "publish-gh=true" >> $GITHUB_ENV |
| 73 | + else |
| 74 | + echo "publish-gh=${{ inputs.publish-gh }}" >> $GITHUB_ENV |
| 75 | + fi |
| 76 | + fi |
| 77 | +
|
| 78 | + - name: Set version |
| 79 | + if: env.UPDATED == 'false' # only change new version if it's not already updated |
| 80 | + run: sed -i "s/mod_version.*=.*/mod_version = ${{ github.event.inputs.version }}/g" gradle.properties |
| 81 | + |
| 82 | + - name: Commit and push gradle.properties |
| 83 | + if: env.UPDATED == 'false' # only push new version if it's not already updated |
| 84 | + uses: stefanzweifel/git-auto-commit-action@v4 |
| 85 | + with: |
| 86 | + commit_message: "Bump version to ${{ github.event.inputs.version }}" |
| 87 | + commit_options: "--no-verify" |
| 88 | + file_pattern: gradle.properties |
| 89 | + tagging_message: "v${{ github.event.inputs.version }}" |
| 90 | + |
| 91 | + - name: Check for publishing |
| 92 | + run: | |
| 93 | + if [ "$publish-gh" == "false" ] && [ "${{ inputs.publish-cf-mr }}" == "false" ] && [ "${{ inputs.publish-maven }}" == "false" ]; then |
| 94 | + echo "Not publishing to Github, Curse, Modrinth or Maven." |
| 95 | + exit 0 |
| 96 | + fi |
| 97 | +
|
| 98 | + - name: Setup Java |
| 99 | + uses: actions/setup-java@v3 |
| 100 | + with: |
| 101 | + distribution: 'temurin' |
| 102 | + java-version: '8' |
| 103 | + |
| 104 | + - name: Grant execute permission for gradlew |
| 105 | + run: chmod +x gradlew |
| 106 | + |
| 107 | + - name: Build jars |
| 108 | + uses: gradle/gradle-build-action@v2 |
| 109 | + with: |
| 110 | + arguments: build |
| 111 | + |
| 112 | + - name: Publish to GitHub |
| 113 | + if: env.publish-gh == 'true' |
| 114 | + uses: softprops/action-gh-release@v1 |
| 115 | + with: |
| 116 | + tag_name: "v${{ inputs.version }}" |
| 117 | + token: ${{ secrets.PAT }} |
| 118 | + files: "build/libs/*.jar" |
| 119 | + generate_release_notes: true |
| 120 | + fail_on_unmatched_files: true |
| 121 | + |
| 122 | + - name: Get Changelog |
| 123 | + run: | |
| 124 | + mkdir -p build |
| 125 | + RELEASE_URL="https://api.github.com/repos/${{ github.repository }}/releases/tags/v${{ inputs.version }}" |
| 126 | + RELEASE_JSON=$(curl -sSL $RELEASE_URL) |
| 127 | + CHANGELOG="$(echo $RELEASE_JSON | jq -r '.body')" |
| 128 | + if [ "$CHANGELOG" == "null" ]; then |
| 129 | + echo "No changelog found" > build/changelog.md |
| 130 | + else |
| 131 | + echo "$CHANGELOG" > build/changelog.md |
| 132 | + fi |
| 133 | +
|
| 134 | + - name: Publish Minecraft Mods |
| 135 | + if: ${{ inputs.publish-cf-mr }} |
| 136 | + uses: Kir-Antipov/[email protected] |
| 137 | + with: |
| 138 | + curseforge-id: 624243 |
| 139 | + curseforge-token: ${{ secrets.CURSEFORGE_TOKEN }} |
| 140 | + |
| 141 | + modrinth-id: Ecvd12QC |
| 142 | + modrinth-featured: true |
| 143 | + modrinth-token: ${{ secrets.MODRINTH_TOKEN }} |
| 144 | + |
| 145 | + files-primary: build/libs/!(*-@(dev|sources|javadoc)).jar |
| 146 | + files-secondary: build/libs/*-@(dev|sources|javadoc).jar |
| 147 | + name: "${GITHUB_REPOSITORY#*/}-${{ github.event.inputs.version }}" |
| 148 | + version: ${{ github.event.inputs.version }} |
| 149 | + version-type: ${{ github.event.inputs.release-type }} |
| 150 | + changelog-file: build/changelog.md |
| 151 | + loaders: | |
| 152 | + forge |
| 153 | + game-versions: | |
| 154 | + 1.12.2 |
| 155 | + dependencies: | |
| 156 | + |
| 157 | + jei(optional) |
| 158 | + hei(optional) |
| 159 | + blur(optional) |
| 160 | + java: | |
| 161 | + 8 |
| 162 | + retry-attempts: 2 |
| 163 | + |
| 164 | + - name: Publish to maven |
| 165 | + if: ${{ inputs.publish-maven }} |
| 166 | + uses: gradle/gradle-build-action@v2 |
| 167 | + with: |
| 168 | + arguments: publish |
| 169 | + env: |
| 170 | + MAVEN_USERNAME: ${{ secrets.MAVEN_NAME }} |
| 171 | + MAVEN_PASSWORD: ${{ secrets.MAVEN_PASSWORD }} |
0 commit comments