Release #30
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: Release | |
on: workflow_dispatch | |
jobs: | |
build: | |
runs-on: ubuntu-22.04 | |
steps: | |
- uses: actions/checkout@v4 | |
- name: setup jdk | |
uses: actions/setup-java@v4 | |
with: | |
java-version: 17 | |
distribution: temurin | |
cache: gradle | |
- name: gradle setup | |
uses: gradle/actions/setup-gradle@v3 | |
- name: gradle build | |
run: ./gradlew build --no-daemon | |
- name: set params | |
run: | | |
cat $GITHUB_WORKSPACE/gradle.properties | grep ^archives_base_name= >> $GITHUB_ENV | |
cat $GITHUB_WORKSPACE/gradle.properties | grep ^minecraft_version= >> $GITHUB_ENV | |
cat $GITHUB_WORKSPACE/gradle.properties | grep ^mod_version= >> $GITHUB_ENV | |
- name: set package name | |
run: echo "pkg_file=$archives_base_name-$mod_version.jar" >> $GITHUB_ENV | |
- name: create release | |
id: create_release | |
uses: actions/github-script@v7 | |
with: | |
script: | | |
const release = await github.rest.repos.createRelease({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
tag_name: `v${{ env.mod_version }}`, | |
name: `v${{ env.mod_version }}`, | |
draft: false, | |
prerelease: false, | |
}); | |
return release.data.upload_url; | |
result-encoding: string | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: upload release asset | |
uses: actions/github-script@v7 | |
with: | |
script: | | |
const fs = require('fs'); | |
const path = require('path'); | |
const uploadUrl = '${{ steps.create_release.outputs.result }}'; | |
const uploadFiles = (dir) => { | |
fs.readdirSync(dir).forEach(file => { | |
const filePath = path.join(dir, file); | |
if (fs.lstatSync(filePath).isFile() && !file.endsWith('-dev.jar') && !file.endsWith('-shadow.jar') && !file.endsWith('-transformProduction.jar')) { | |
const content = fs.readFileSync(filePath); | |
github.rest.repos.uploadReleaseAsset({ | |
url: uploadUrl, | |
headers: { | |
'content-length': content.length, | |
'content-type': 'application/java-archive' | |
}, | |
name: path.basename(filePath), | |
data: content | |
}); | |
} | |
}); | |
}; | |
const forgeDir = path.join(process.cwd(), 'forge/build/libs'); | |
const fabricDir = path.join(process.cwd(), 'fabric/build/libs'); | |
uploadFiles(forgeDir); | |
uploadFiles(fabricDir); | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |