Skip to content

Commit c0840db

Browse files
committed
init
0 parents  commit c0840db

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

99 files changed

+778
-0
lines changed

.github/workflows/publish.yml

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
name: Publish Pack
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
7+
permissions:
8+
contents: write
9+
actions: read
10+
11+
concurrency:
12+
group: ${{ github.workflow }}-${{ github.ref }}
13+
cancel-in-progress: true
14+
15+
jobs:
16+
build:
17+
runs-on: ubuntu-latest
18+
19+
steps:
20+
- name: Checkout repo
21+
uses: actions/checkout@v4
22+
with:
23+
fetch-depth: 0
24+
submodules: recursive
25+
26+
- name: Get Pack Meta
27+
id: meta
28+
run: |
29+
NAME=$(jq -r '.name' pack_meta.json)
30+
VERSION=$(jq -r '.version' pack_meta.json)
31+
MC=$(jq -r '.mc_version' pack_meta.json)
32+
SUPPORTED_MC=$(jq -rc '.supported_mc_versions' pack_meta.json)
33+
PACK_ID=${VERSION}+mc${MC}
34+
35+
echo "PACK_NAME=$NAME" >> "$GITHUB_OUTPUT"
36+
echo "PACK_VERSION=$VERSION" >> "$GITHUB_OUTPUT"
37+
echo "MC_VERSION=$MC" >> "$GITHUB_OUTPUT"
38+
echo "SUPPORTED_MC_VERSIONS=$SUPPORTED_MC" >> "$GITHUB_OUTPUT"
39+
echo "PACK_ID=$PACK_ID" >> "$GITHUB_OUTPUT"
40+
echo "PACK_FILENAME=${NAME}_${PACK_ID}.zip" >> "$GITHUB_OUTPUT"
41+
42+
echo "COMMIT_SHORT_HASH=$(git rev-parse --short HEAD)" >> "$GITHUB_OUTPUT"
43+
44+
- name: Zip Pack
45+
run: |
46+
mkdir -p dist
47+
cd src
48+
zip -r ../dist/${{ steps.meta.outputs.PACK_FILENAME }} ./
49+
50+
- name: Upload Pack
51+
uses: actions/upload-artifact@v4
52+
with:
53+
name: ${{ steps.meta.outputs.PACK_FILENAME }}
54+
path: dist/${{ steps.meta.outputs.PACK_FILENAME }}
55+
56+
- name: Check GitHub Release Tag
57+
id: ghcheck
58+
env:
59+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
60+
run: |
61+
CODE=$(curl -s -o /dev/null -w "%{http_code}" \
62+
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
63+
-H "X-GitHub-Api-Version: 2022-11-28" \
64+
"https://api.github.com/repos/${{ github.repository }}/releases/tags/${{ steps.meta.outputs.PACK_ID }}")
65+
66+
[ "$CODE" = "200" ] && EXISTS=true || EXISTS=false
67+
echo "EXISTS=$EXISTS" >> "$GITHUB_OUTPUT"
68+
69+
- name: Create Release
70+
if: ${{ steps.ghcheck.outputs.EXISTS != 'true' }}
71+
uses: softprops/action-gh-release@v2
72+
with:
73+
tag_name: ${{ steps.meta.outputs.PACK_ID }}
74+
name: ${{ steps.meta.outputs.PACK_NAME }} ${{ steps.meta.outputs.PACK_VERSION }} for Minecraft ${{ steps.meta.outputs.MC_VERSION }}
75+
files: dist/${{ steps.meta.outputs.PACK_FILENAME }}
76+
env:
77+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
78+
79+
- name: Has Modrinth Token
80+
id: hastoken
81+
env:
82+
TOKEN: ${{ secrets.MODRINTH_TOKEN }}
83+
run: |
84+
echo "EXISTS=$([ -n "$TOKEN" ] && echo true || echo false)" >> "$GITHUB_OUTPUT"
85+
86+
- name: Fetch Modrinth Info
87+
id: modrinthinfo
88+
if: ${{ steps.hastoken.outputs.EXISTS == 'true' }}
89+
env:
90+
MODRINTH_TOKEN: ${{ secrets.MODRINTH_TOKEN }}
91+
run: |
92+
PROJECT_ID=$(curl -s "https://api.modrinth.com/v2/project/legacy-mc-tweaks" -H "Authorization: Bearer $MODRINTH_TOKEN" | jq -r '.id')
93+
VERSION_EXISTS=$(curl -s -H "User-Agent: github-actions" "https://api.modrinth.com/v2/project/${PROJECT_ID}/version" -H "Authorization: Bearer $MODRINTH_TOKEN" | jq -r --arg v "${{ steps.meta.outputs.PACK_ID }}" 'if type == "array" then any(.[]; (.version_number? // "") == $v) else false end')
94+
echo "PROJECT_ID=$PROJECT_ID" >> "$GITHUB_OUTPUT"
95+
echo "VERSION_EXISTS=$VERSION_EXISTS" >> "$GITHUB_OUTPUT"
96+
97+
- name: Publish Pack to Modrinth
98+
uses: cloudnode-pro/modrinth-publish@v2
99+
if: ${{ steps.hastoken.outputs.EXISTS == 'true' && steps.modrinthinfo.outputs.VERSION_EXISTS != 'true' }}
100+
with:
101+
token: ${{ secrets.MODRINTH_TOKEN }}
102+
project: ${{ steps.modrinthinfo.outputs.PROJECT_ID }}
103+
name: ${{ steps.meta.outputs.PACK_NAME }}
104+
version: ${{ steps.meta.outputs.PACK_ID }}
105+
files: '["dist/${{ steps.meta.outputs.PACK_FILENAME }}"]'
106+
primary-file: ${{ steps.meta.outputs.PACK_FILENAME }}
107+
game-versions: "${{ steps.meta.outputs.SUPPORTED_MC_VERSIONS }}"
108+
loaders: '["minecraft"]'

0 commit comments

Comments
 (0)