rework workflows
This commit is contained in:
parent
5d91cb6e96
commit
b38c999948
4 changed files with 453 additions and 156 deletions
317
.github/workflows/build.yml
vendored
Normal file
317
.github/workflows/build.yml
vendored
Normal file
|
|
@ -0,0 +1,317 @@
|
|||
name: Build
|
||||
run-name: "Build #${{ github.run_number }}"
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- "*.*.*"
|
||||
branches:
|
||||
- main
|
||||
|
||||
concurrency:
|
||||
group: ${{ github.ref }}
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
modpack-info:
|
||||
name: Modpack Info
|
||||
runs-on: ubuntu-latest
|
||||
outputs:
|
||||
project_name: ${{ steps.info.outputs.project_name }}
|
||||
project_version: ${{ steps.info.outputs.project_version }}
|
||||
mcversion: ${{ steps.info.outputs.mcversion }}
|
||||
tag: ${{ steps.version.outputs.tag }}
|
||||
changelog: ${{ steps.changelog_full.outputs.description }}
|
||||
steps:
|
||||
- name: Checkout with fetch depth 2
|
||||
uses: actions/checkout@v4.1.1
|
||||
with:
|
||||
fetch-depth: 2
|
||||
|
||||
- name: Get tag
|
||||
id: version
|
||||
uses: "WyriHaximus/github-action-get-previous-tag@v1.3.0"
|
||||
with:
|
||||
fallback: tag_not_found
|
||||
|
||||
- name: Modpack info
|
||||
id: info
|
||||
run: |
|
||||
set +e
|
||||
|
||||
if [ ! -f ./.github/buildtools/modpack/manifest.json ]; then
|
||||
echo "::error::Could not find manifest.json" && exit 1
|
||||
fi
|
||||
manifestjson=`cat ./.github/buildtools/modpack/manifest.json`
|
||||
|
||||
project_name=`echo $(jq -r '.name' <<< "$manifestjson")`
|
||||
echo "project_name=$project_name" >> $GITHUB_OUTPUT
|
||||
|
||||
mcversion=`echo $(jq -r '.minecraft.version' <<< "$manifestjson")`
|
||||
echo "mcversion=$mcversion" >> $GITHUB_OUTPUT
|
||||
|
||||
if [[ ${{ startsWith(github.ref, 'refs/tags/') }} == true ]]; then
|
||||
echo "project_version=${{ steps.version.outputs.tag }}" >> $GITHUB_OUTPUT
|
||||
else
|
||||
echo "project_version=build.${{ github.run_number }}" >> $GITHUB_OUTPUT
|
||||
fi
|
||||
|
||||
- name: Checkout with fetch depth 0
|
||||
uses: actions/checkout@v4.1.1
|
||||
with:
|
||||
fetch-depth: 0
|
||||
- name: Process changelog
|
||||
id: mod_changes
|
||||
shell: bash
|
||||
run: |
|
||||
set +e
|
||||
|
||||
curl https://github.com/josephburnett/jd/releases/download/v1.7.1/jd-amd64-linux -o ./pax/jd -L -J
|
||||
sudo chmod +x ./pax/jd
|
||||
|
||||
manifest="./.github/buildtools/modpackmanifest.json"
|
||||
changelog="./CHANGELOG.md"
|
||||
|
||||
branch=$(git rev-parse --abbrev-ref HEAD)
|
||||
current_commit=$(git rev-parse --short ${{ github.sha }})
|
||||
previous_commit=$(git log -n 1 --skip 1 --pretty=format:"%h" -- $manifest)
|
||||
latest_commit=$(git log -n 1 --pretty=format:"%h" $branch -- $manifest)
|
||||
latest_tag=$(git describe --tags --abbrev=0)
|
||||
latest_tagged_commit=$(git rev-list -n 1 --pretty=format:"%h" $latest_tag | sed -n 2p)
|
||||
|
||||
if [ "$latest_tag" = ${{ steps.version.outputs.tag }} ]; then
|
||||
latest_tag=$(git describe --tags --abbrev=0 $(git describe --tags --abbrev=0)^)
|
||||
latest_tagged_commit=$(git rev-list -n 1 --pretty=format:"%h" $latest_tag | sed -n 2p)
|
||||
fi
|
||||
|
||||
if [ "$latest_commit" = "$current_commit" ]; then
|
||||
echo "changed=true" >> $GITHUB_OUTPUT
|
||||
else
|
||||
echo "changed=false" >> $GITHUB_OUTPUT
|
||||
fi
|
||||
|
||||
echo "branch: $branch"
|
||||
echo "current commit: $current_commit"
|
||||
echo "previous commit: $previous_commit"
|
||||
echo "latest commit: $latest_commit"
|
||||
echo "latest tagged commit: $latest_tagged_commit"
|
||||
echo "latest tag: $latest_tag"
|
||||
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
BLUE='\033[0;36m'
|
||||
NC='\033[0m'
|
||||
|
||||
git show $latest_tagged_commit:$manifest > ./.github/buildtools/modpackmanifest_prev.json
|
||||
mods_removed_raw=$(./pax/jd -set ./.github/buildtools/modpackmanifest_prev.json $manifest | grep '^-' | grep -P -o '"name":[\s]*"\K[^"]*' | tr -d '\[\]')
|
||||
mods_added_raw=$(./pax/jd -set ./.github/buildtools/modpackmanifest_prev.json $manifest | grep '^+' | grep -P -o '"name":[\s]*"\K[^"]*' | tr -d '\[\]')
|
||||
|
||||
mods_added=""
|
||||
mods_removed=""
|
||||
mods_updated=""
|
||||
|
||||
mod_changes=""
|
||||
|
||||
if [[ ! -z ""$mods_added_raw"" ]]; then
|
||||
while IFS= read -r line1; do
|
||||
foo=""
|
||||
while IFS= read -r line2; do
|
||||
foo="${line1//$line2}"
|
||||
if [[ -z ""$foo"" ]]; then
|
||||
if [[ ! -z ""$mods_updated"" ]]; then
|
||||
mods_updated+="\n"
|
||||
fi
|
||||
mods_updated+="- $line1"
|
||||
break
|
||||
fi
|
||||
done <<< "$mods_removed_raw"
|
||||
if [[ ! -z ""$foo"" ]]; then
|
||||
if [[ ! -z ""$mods_added"" ]]; then
|
||||
mods_added+="\n"
|
||||
fi
|
||||
mods_added+="- $foo"
|
||||
fi
|
||||
done <<< "$mods_added_raw"
|
||||
fi
|
||||
|
||||
if [[ ! -z ""$mods_removed_raw"" ]]; then
|
||||
while IFS= read -r line1; do
|
||||
bar=""
|
||||
while IFS= read -r line2; do
|
||||
bar="${line1//$line2}"
|
||||
if [[ -z ""$bar"" ]]; then
|
||||
break
|
||||
fi
|
||||
done <<< "$mods_added_raw"
|
||||
if [[ ! -z ""$bar"" ]]; then
|
||||
if [[ ! -z ""$mods_removed"" ]]; then
|
||||
mods_removed+="\n"
|
||||
fi
|
||||
mods_removed+="- $bar"
|
||||
fi
|
||||
done <<< "$mods_removed_raw"
|
||||
fi
|
||||
|
||||
if [[ ! -z ""$mods_added"" ]] || [[ ! -z ""$mods_removed"" ]] || [[ ! -z ""$mods_updated"" ]]; then
|
||||
echo -e "x---------------x"
|
||||
echo -e "| Mod Changes |"
|
||||
|
||||
mod_changes+="## Mod Changes\n\n"
|
||||
mod_changes+="Since: [\`$latest_tag\`](<https://github.com/${{ github.repository }}/releases/tag/$latest_tag>)\n\n"
|
||||
mod_changes+="\`\`\`markdown\n"
|
||||
fi
|
||||
|
||||
if [[ ! -z ""$mods_added"" ]]; then
|
||||
echo -e "${GREEN}Added:"
|
||||
echo -e "$mods_added"
|
||||
|
||||
mod_changes+="Added:\n"
|
||||
mod_changes+="$mods_added\n"
|
||||
|
||||
if [[ ! -z ""$mods_removed"" ]] || [[ ! -z ""$mods_updated"" ]]; then
|
||||
mod_changes+="\n"
|
||||
fi
|
||||
fi
|
||||
if [[ ! -z ""$mods_removed"" ]]; then
|
||||
echo -e "${RED}Removed:"
|
||||
echo -e "$mods_removed"
|
||||
|
||||
mod_changes+="Removed:\n"
|
||||
mod_changes+="$mods_removed\n"
|
||||
|
||||
if [[ ! -z ""$mods_updated"" ]]; then
|
||||
mod_changes+="\n"
|
||||
fi
|
||||
fi
|
||||
if [[ ! -z ""$mods_updated"" ]]; then
|
||||
echo -e "${BLUE}Updated:"
|
||||
echo -e "$mods_updated"
|
||||
|
||||
mod_changes+="Updated:\n"
|
||||
mod_changes+="$mods_updated\n"
|
||||
fi
|
||||
|
||||
if [[ ! -z ""$mods_added"" ]] || [[ ! -z ""$mods_removed"" ]] || [[ ! -z ""$mods_updated"" ]]; then
|
||||
echo -e "${NC}x---------------x"
|
||||
|
||||
mod_changes+="\`\`\`"
|
||||
fi
|
||||
|
||||
if [[ ! -z ""$mod_changes"" ]]; then
|
||||
echo -e "$mod_changes" >> $GITHUB_STEP_SUMMARY
|
||||
fi
|
||||
|
||||
# Upload @mod_changes@
|
||||
mod_changes=$(echo $mod_changes | sed -r 's/[/]/\\\//g')
|
||||
perl -i -pe "s/\@mod_changes\@/$mod_changes/g" $changelog
|
||||
|
||||
# Replace @mod_changes@
|
||||
mod_changes=$(echo $mod_changes | sed -r 's/\\\\n/\\n/g')
|
||||
echo "markdown=$mod_changes" >> $GITHUB_OUTPUT
|
||||
|
||||
rm ./.github/buildtools/modpack/manifest_prev.json
|
||||
|
||||
# Replace @version@
|
||||
perl -i -pe "s/\@version\@/${{ steps.info.outputs.projectsuffix }}/g" $changelog
|
||||
|
||||
# Finally, Rename changelog
|
||||
mv $changelog CHANGELOG-${{ steps.info.outputs.projectsuffix }}.md
|
||||
- name: Upload changelog
|
||||
uses: actions/upload-artifact@v4.0.0
|
||||
with:
|
||||
name: changelog
|
||||
path: CHANGELOG-${{ steps.info.outputs.projectsuffix }}.md
|
||||
|
||||
- name: Changelog Parser
|
||||
id: changelog_full
|
||||
uses: coditory/changelog-parser@v1.0.2
|
||||
with:
|
||||
path: CHANGELOG.md
|
||||
|
||||
build-modpack:
|
||||
name: Build Modpack
|
||||
runs-on: ubuntu-latest
|
||||
needs: [modpack-info]
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4.1.1
|
||||
|
||||
- name: Replace strings
|
||||
shell: bash
|
||||
run: |
|
||||
VERSION=${{ needs.modpack-info.outputs.project_version }}
|
||||
sed -i -e "s/DEV/${VERSION}/g" ./.github/buildtools/modpack/manifest.json
|
||||
sed -i -e "s/DEV/${VERSION}/g" ./.github/buildtools/modpack/instance.cfg
|
||||
sed -i -e "s/DEV/${VERSION}/g" config/fancymenu/customization/main_menu.txt
|
||||
sed -i -e "s/DEV/${VERSION}/g" config/bcc-common.toml
|
||||
|
||||
- name: Export CF
|
||||
run: |
|
||||
mkdir -p overrides
|
||||
cp -r {config,defaultconfigs,kubejs} overrides/
|
||||
mv -vf .github/buildtools/modpack/manifest.json ./
|
||||
mv -vf .github/buildtools/modpack/modlist.html ./
|
||||
zip -r ${{ needs.modpack-info.outputs.project_name }}-${{ needs.modpack-info.outputs.project_version }}-cf.zip manifest.json modlist.html overrides
|
||||
|
||||
- name: Export MMC
|
||||
run: |
|
||||
cp -r mods overrides/
|
||||
mv -vf overrides/ .minecraft/
|
||||
mv -vf .github/buildtools/modpack/mmc-pack.json ./
|
||||
mv -vf .github/buildtools/modpack/instance.cfg ./
|
||||
zip -r ${{ needs.modpack-info.outputs.project_name }}-${{ needs.modpack-info.outputs.project_version }}-mmc.zip mmc-pack.json instance.cfg .minecraft/
|
||||
|
||||
- name: Upload zip cf
|
||||
uses: actions/upload-artifact@v4.0.0
|
||||
with:
|
||||
name: modpack_cf
|
||||
path: ${{ needs.modpack-info.outputs.project_name }}-${{ needs.modpack-info.outputs.project_version }}-cf.zip
|
||||
|
||||
- name: Upload zip mmc
|
||||
uses: actions/upload-artifact@v4.0.0
|
||||
with:
|
||||
name: modpack_mmc
|
||||
path: ${{ needs.modpack-info.outputs.project_name }}-${{ needs.modpack-info.outputs.project_version }}-mmc.zip
|
||||
|
||||
build-serverpack:
|
||||
name: Build Serverpack
|
||||
runs-on: ubuntu-latest
|
||||
needs: [modpack-info]
|
||||
if: startsWith(github.ref, 'refs/tags/v')
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4.1.1
|
||||
|
||||
- name: Download Mods
|
||||
run: |
|
||||
git submodule init
|
||||
cd mods
|
||||
git config --local ${{ secrets.GITHUB_TOKEN }}
|
||||
git submodule update --recursive
|
||||
|
||||
- name: Export serverpack
|
||||
run: |
|
||||
cp -r .github/buildtools/serverpack/* .minecraft/
|
||||
cat .github/buildtools/client_mod.txt | while read -r line; do find .minecraft/mods -name "$line" -delete; done
|
||||
cd .minecraft/
|
||||
zip -r ${{ needs.modpack-info.outputs.project_name }}-${{ needs.modpack-info.outputs.project_version }}-server.zip ./
|
||||
|
||||
- name: Upload zip
|
||||
uses: actions/upload-artifact@v4.0.0
|
||||
with:
|
||||
name: server_pack
|
||||
path: ${{ needs.modpack-info.outputs.project_name }}-${{ needs.modpack-info.outputs.project_version }}-server.zip
|
||||
|
||||
release:
|
||||
name: Release
|
||||
needs: [modpack-info, build-modpack, build-serverpack]
|
||||
if: startsWith(github.ref, 'refs/tags/')
|
||||
uses: ./.github/workflows/release.yml
|
||||
with:
|
||||
project_name: ${{ needs.modpack-info.outputs.project_name }}
|
||||
project_version: ${{ needs.modpack-info.outputs.project_version }}
|
||||
mcversion: ${{ needs.modpack-info.outputs.mcversion }}
|
||||
tag: ${{ needs.modpack-info.outputs.tag }}
|
||||
changelog: ${{ needs.modpack-info.outputs.changelog }}
|
||||
secrets: inherit
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue