Skip to content

Commit 381ee68

Browse files
committed
feat: 提交即构建
1 parent 3aa73ad commit 381ee68

2 files changed

Lines changed: 74 additions & 3 deletions

File tree

.github/workflows/commit-build.yml

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
name: "Commit and Build TelegramChat"
2+
3+
on:
4+
push:
5+
branches: ['master']
6+
7+
jobs:
8+
build-and-release:
9+
runs-on: ubuntu-latest
10+
name: "Check and Package"
11+
steps:
12+
- name: "Checkout"
13+
uses: actions/checkout@v4
14+
15+
- name: "Generate Short Hash"
16+
id: short_hash
17+
run: |
18+
SHORT_HASH=$(echo "${{ github.sha }}" | cut -c1-7)
19+
echo "short_hash=$SHORT_HASH" >> $GITHUB_OUTPUT
20+
21+
- name: "Install Python"
22+
run: |
23+
sudo apt-get update
24+
sudo apt-get install -y python3 python3-pip git zip
25+
26+
- name: "Check Version from Files"
27+
id: check_version
28+
run: |
29+
PLUGIN_VERSION=$(jq -r '.version' mcdreforged.plugin.json)
30+
31+
echo "Plugin version from mcdreforged.plugin.json: $PLUGIN_VERSION"
32+
33+
PYTHON_VERSION=$(python -c "import importlib.util, sys; spec = importlib.util.spec_from_file_location('version', 'telegram_chat/const.py'); version = importlib.util.module_from_spec(spec); sys.modules['version'] = version; spec.loader.exec_module(version); print(version.VERSION_STR)")
34+
35+
echo "Python VERSION_STR: $PYTHON_VERSION"
36+
37+
if [ "$PLUGIN_VERSION" != "$PYTHON_VERSION" ]; then
38+
echo "Version mismatch: Plugin version and Python VERSION_STR do not match."
39+
exit 1
40+
else
41+
echo "Version match: Proceeding with the build."
42+
fi
43+
44+
echo "version=$TAG_VERSION" >> $GITHUB_OUTPUT
45+
46+
- name: "Create Exclude List from .packignore"
47+
id: exclude_list
48+
run: |
49+
# Check if .packignore exists and create an exclude list
50+
if [ -f ".packignore" ]; then
51+
# Read the .packignore file and format for zip exclusion
52+
EXCLUDE_LIST=$(cat .packignore | sed 's|^|"|' | sed 's|$|"|' | tr '\n' ' ')
53+
echo "Exclude list: $EXCLUDE_LIST"
54+
echo "exclude_list=-x $EXCLUDE_LIST" >> $GITHUB_OUTPUT
55+
else
56+
echo ".packignore not found, no files will be excluded."
57+
echo "exclude_list=" >> $GITHUB_OUTPUT
58+
fi
59+
60+
- name: "Package the Plugin"
61+
run: |
62+
# Create the zip file excluding files listed in .packignore
63+
zip -r TelegramChat-${{ steps.check_version.outputs.version }}-beta-${{ steps.short_hash.outputs.short_hash }}.zip * \
64+
${{ steps.exclude_list.outputs.exclude_list }}
65+
mv TelegramChat-${{ steps.check_version.outputs.version }}-beta-${{ steps.short_hash.outputs.short_hash }}.zip TelegramChat-${{ steps.check_version.outputs.version }}-beta-${{ steps.short_hash.outputs.short_hash }}.mcdr
66+
67+
- name: "Upload Artifact"
68+
uses: actions/upload-artifact@v4
69+
with:
70+
name: "TelegramChat-${{ steps.check_version.outputs.version }}-beta-${{ steps.short_hash.outputs.short_hash }}.mcdr"
71+
path: "TelegramChat-${{ steps.check_version.outputs.version }}-beta-${{ steps.short_hash.outputs.short_hash }}.mcdr"

.github/workflows/tag-and-release.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: "Build and Release TelegramChat"
1+
name: "Check, Package and Release TelegramChat"
22

33
on:
44
push:
@@ -8,7 +8,7 @@ on:
88
jobs:
99
build-and-release:
1010
runs-on: ubuntu-latest
11-
name: "Build, Package and Release"
11+
name: "Check, Package and Release"
1212
steps:
1313
- name: "Checkout Code"
1414
uses: actions/checkout@v4
@@ -63,7 +63,7 @@ jobs:
6363
echo "exclude_list=" >> $GITHUB_OUTPUT
6464
fi
6565
66-
- name: "Build and Package the Plugin"
66+
- name: "Package the Plugin"
6767
run: |
6868
# Create the zip file excluding files listed in .packignore
6969
zip -r TelegramChat-${{ steps.check_version.outputs.version }}.zip * \

0 commit comments

Comments
 (0)