rework workflows

This commit is contained in:
Xikaro 2024-01-05 00:32:59 +05:00
parent 5d91cb6e96
commit b38c999948
4 changed files with 453 additions and 156 deletions

317
.github/workflows/build.yml vendored Normal file
View 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

View file

@ -1,68 +0,0 @@
name: Deploy modpack preview
on:
push:
tags:
- "Pre*"
jobs:
Deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4.1.1
- name: Get the version
id: get_version
run: echo ::set-output name=version::${GITHUB_REF#refs/tags/Pre}
- name: Set the version
run: |
DEV=${{ steps.get_version.outputs.version }}
sed -i -e "s/DEV/${DEV}/g" .github/buildtools/modpack/manifest.json
sed -i -e "s/DEV/${DEV}/g" .github/buildtools/modpack/instance.cfg
sed -i -e "s/DEV/${DEV}/g" config/fancymenu/customization/main_menu.txt
sed -i -e "s/DEV/${DEV}/g" config/bcc-common.toml
- name: Changelog Parser
id: changelog
uses: coditory/changelog-parser@v1.0.2
with:
path: CHANGELOG.md
- name: Submodule init
run: |
git submodule init
cd mods
git config --global credential.helper '!f() { echo "username=Xikaro"; echo "password=${{ secrets.USER_TOKEN_XIKARO }}"; }; f'
git submodule update --recursive
- name: Archive CF
run: |
cp -r {config,defaultconfigs,kubejs,mods} overrides/
zip -r ./TerraFirmaGreg-1.20.x-${{ steps.get_version.outputs.version }}-cf.zip .github/buildtools/modpack/manifest.json .github/buildtools/modpack/modlist.html overrides
- name: Archive MMC
run: |
mv -vf overrides/ .minecraft/
zip -r ./TerraFirmaGreg-1.20.x-${{ steps.get_version.outputs.version }}-mmc.zip .github/buildtools/modpack/mmc-pack.json .github/buildtools/modpack/instance.cfg .minecraft/
- name: Archive Server
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 ../TerraFirmaGreg-1.20.x-${{ steps.get_version.outputs.version }}-server.zip ./
- name: Create GitHub Release
uses: softprops/action-gh-release@v0.1.15
if: startsWith(github.ref, 'refs/tags/')
with:
prerelease: true
generate_release_notes: true
name: ${{ steps.changelog.outputs.version }}
body: ${{ steps.changelog.outputs.description }}
files: |
./TerraFirmaGreg-1.20-${{ steps.get_version.outputs.version }}-cf.zip
./TerraFirmaGreg-1.20-${{ steps.get_version.outputs.version }}-mmc.zip
./TerraFirmaGreg-1.20-${{ steps.get_version.outputs.version }}-server.zip

View file

@ -2,116 +2,165 @@ name: Release
run-name: "Release #${{ github.run_number }}"
on:
push:
tags:
- "*.*.*"
workflow_call:
inputs:
project_name:
required: true
type: string
project_version:
required: true
type: string
mcversion:
required: true
type: string
tag:
required: true
type: string
changelog:
required: true
type: string
env:
CF_PROJECT_ID: "399664"
MODRINTH_PROJECT_ID: "75JuuMzk"
RELEASE_TYPE: "beta"
jobs:
Deploy:
release-github:
name: Deploy to GitHub
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4.1.1
- name: Get the version
id: get_version
run: echo ::set-output name=version::${GITHUB_REF#refs/tags/}
- name: Get tag
id: get_tag
uses: "WyriHaximus/github-action-get-previous-tag@v1.3.0"
- name: Download modpack
uses: actions/download-artifact@v4.1.0
with:
fallback: tag_not_found
pattern: ${{ inputs.project_name }}-${{ inputs.project_version }}-*
merge-multiple: true
- name: Set the version
run: |
DEV=${{ steps.get_version.outputs.version }}
sed -i -e "s/DEV/${DEV}/g" .github/buildtools/modpack/manifest.json
sed -i -e "s/DEV/${DEV}/g" .github/buildtools/modpack/instance.cfg
sed -i -e "s/DEV/${DEV}/g" config/fancymenu/customization/main_menu.txt
sed -i -e "s/DEV/${DEV}/g" config/bcc-common.toml
- name: Changelog Parser
id: changelog
uses: coditory/changelog-parser@v1.0.2
- name: Download changelog
uses: actions/download-artifact@v4.1.0
with:
path: CHANGELOG.md
name: changelog
- name: Submodule init
run: |
git submodule init
cd mods
git config --local ${{ secrets.GITHUB_TOKEN }}
git submodule update --recursive
- name: Create release
uses: softprops/action-gh-release@v1
with:
prerelease: false
generate_release_notes: true
name: ${{ inputs.project_version }}
body: ${{ inputs.changelog }}
files: |
${{ inputs.project_name }}-${{ inputs.project_version }}-cf.zip
${{ inputs.project_name }}-${{ inputs.project_version }}-mmc.zip
${{ inputs.project_name }}-${{ inputs.project_version }}-server.zip
tag_name: ${{ inputs.tag }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Archive CF
release-curseforge:
name: Deploy to CurseForge
runs-on: ubuntu-latest
steps:
- name: Check if CF_API_TOKEN exist
shell: bash
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 ./TerraFirmaGreg-1.20.x-${{ steps.get_version.outputs.version }}-cf.zip manifest.json modlist.html overrides
if [ "${{ secrets.CF_API_TOKEN }}" == '' ]; then
echo '::error::No value found for secret key `CF_API_TOKEN`. See https://docs.github.com/en/actions/security-guides/encrypted-secrets#creating-encrypted-secrets-for-a-repository' && exit 1
fi
- name: Archive 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 ./TerraFirmaGreg-1.20.x-${{ steps.get_version.outputs.version }}-mmc.zip mmc-pack.json instance.cfg .minecraft/
- name: Download modpack
uses: actions/download-artifact@v4.1.0
with:
name: modpack_cf
- name: Archive Server
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 ../TerraFirmaGreg-1.20.x-${{ steps.get_version.outputs.version }}-server.zip ./
- name: Download serverpack
uses: actions/download-artifact@v4.1.0
with:
name: server_pack
- name: Upload Curseforge
id: cf_release
uses: SwitchAlpha/upload-curseforge-modpack-action@master
with:
api-token: ${{ secrets.CF_API_TOKEN }}
project-id: "385053"
modpack-path: ./TerraFirmaGreg-1.20.x-${{ steps.get_version.outputs.version }}-cf.zip
modpack-server-path: ./TerraFirmaGreg-1.20.x-${{ steps.get_version.outputs.version }}-server.zip
changelog: "${{ steps.changelog.outputs.description }}"
project-id: ${{ env.CF_PROJECT_ID }}
modpack-path: ${{ inputs.project_name }}-${{ inputs.project_version }}-cf.zip
modpack-server-path: ${{ inputs.project_name }}-${{ inputs.project_version }}-server.zip
changelog: "${{ inputs.changelog }}"
changelog-format: markdown
game-version: "1.20.1"
display-name: TerraFirmaGreg-1.20.x-${{ steps.get_version.outputs.version }}
server-display-name: TerraFirmaGreg-1.20.x-${{ steps.get_version.outputs.version }}-server
release-type: "beta"
game-version: ${{ inputs.mcversion }}
display-name: ${{ inputs.project_name }}-${{ inputs.project_version }}
server-display-name: ${{ inputs.project_name }}-${{ inputs.project_version }}-server
release-type: ${{ env.RELEASE_TYPE }}
- name: Create GitHub Release
uses: softprops/action-gh-release@v0.1.15
if: startsWith(github.ref, 'refs/tags/')
- name: Create Discord message
id: message
shell: bash
run: |
message="## **${{ inputs.project_name }}** has been updated to ${{ inputs.project_version }}! :tada:\n"
message+="[CurseForge](<https://www.curseforge.com/minecraft/modpacks/terrafirmagreg/files/${{ steps.cf_release.outputs.id }}>) • "
message+="[GitHub](<https://github.com/TerraFirmaGreg-Team/TFG-Modpack-1.20.x/releases/tag/${{ inputs.tag }}>) • "
message+="[Issues](<${{ github.repository.svn_url }}/issues>)\n"
message+="${{ inputs.changelog }}"
echo "markdown=$message" >> $GITHUB_OUTPUT
- name: Send Discord message
uses: hugoalh/send-discord-webhook-ghaction@v6.0.1
with:
prerelease: false
generate_release_notes: true
name: ${{ steps.changelog.outputs.version }}
body: ${{ steps.changelog.outputs.description }}
files: |
./TerraFirmaGreg-1.20.x-${{ steps.get_version.outputs.version }}-cf.zip
./TerraFirmaGreg-1.20.x-${{ steps.get_version.outputs.version }}-mmc.zip
./TerraFirmaGreg-1.20.x-${{ steps.get_version.outputs.version }}-server.zip
key: "${{secrets.RELEASES_1_20}}"
username: "TerraFirmaGreg"
avatar_url: "https://github.com/TerraFirmaGreg-Team/.github/tree/main/branding/logo_new_year.png?raw=true"
content: "${{ steps.message.outputs.markdown }}"
- name: Discord notification
uses: tsickert/discord-webhook@v5.4.0
with:
webhook-url: ${{ secrets.RELEASES_1_20 }}
username: "GitHub"
avatar-url: https://github.com/TerraFirmaGreg-Team/.github/tree/main/branding/logo_new_year.png?raw=true
content: "[CurseForge](<https://legacy.curseforge.com/minecraft/modpacks/terrafirmagreg/files/${{ steps.cf_release.outputs.id }}>)"
embed-title: Release ${{ steps.changelog.outputs.version }}
embed-description: "${{ steps.changelog.outputs.description }}"
embed-url: https://github.com/TerraFirmaGreg-Team/TFG-Modpack-1.20.x/tree/main/CHANGELOG.md
embed-color: 5814783
embed-footer-text: ${{ steps.changelog.outputs.date }}
# release-modrinth:
# name: Deploy to Modrinth
# runs-on: ubuntu-latest
# steps:
# - name: Check if MODRINTH_API_TOKEN exist
# shell: bash
# run: |
# if [ "${{ secrets.MODRINTH_API_TOKEN }}" == '' ]; then
# echo '::error::No value found for secret key `MODRINTH_API_TOKEN`. See https://docs.github.com/en/actionssecurity-guides/ encrypted-secrets#creating-encrypted-secrets-for-a-repository' && exit 1
# fi
- name: Close Fixed in dev
# - name: Download modpack
# uses: actions/download-artifact@v4.1.0
# with:
# name: modpack_mrd
# - name: Download serverpack
# uses: actions/download-artifact@v4.1.0
# with:
# name: server_pack
# - name: Upload Modrinth
# id: cf_release
# uses: SwitchAlpha/upload-curseforge-modpack-action@master
# with:
# api-token: ${{ secrets.MODRINTH_API_TOKEN }}
# project-id: ${{ env.MODRINTH_PROJECT_ID }}
# modpack-path: ${{ inputs.project_name }}-${{ inputs.project_version }}-mrd.zip
# modpack-server-path: ${{ inputs.project_name }}-${{ inputs.project_version }}-server.zip
# changelog: "${{ inputs.changelog }}"
# changelog-format: markdown
# game-version: ${{ inputs.mcversion }}
# display-name: ${{ inputs.project_name }}-${{ inputs.project_version }}
# server-display-name: ${{ inputs.project_name }}-${{ inputs.project_version }}-server
# release-type: ${{ env.RELEASE_TYPE }}
close-fixed-issues:
name: Close Fixed Issues
runs-on: ubuntu-latest
needs: [release-github, release-curseforge]
steps:
- name: Checkout
uses: actions/checkout@v4.1.1
- name: close-fixed-in-dev
uses: juraj-hrivnak/close-issues-based-on-label@master
env:
LABEL: "2. status: fixed in dev"
VERSION: ${{ steps.get_tag.outputs.tag }}
VERSION: ${{ inputs.tag }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}