Skip to content

Update create-release.yml #74

Update create-release.yml

Update create-release.yml #74

name: Create Release with Zipped Branch Assets and Date
on:
workflow_dispatch:
jobs:
release:
runs-on: ubuntu-latest
permissions:
contents: write
actions: write
steps:
- name: Set up environment variables
run: |
echo "CURRENT_DATE=$(date +'%Y%m%d')" >> $GITHUB_ENV
echo "RELEASE_TITLE=$(date +'%Y.%m.%d') 词库更新" >> $GITHUB_ENV
- name: Checkout main branch
uses: actions/checkout@v4
- name: Create directories
run: |
mkdir -p Rime
mkdir -p mb/xmjd6
- name: Zip main branch files excluding .git and .github
run: zip -r xmjd6.zip . -x "*.git*" -x "*.github*" -x "yong*" -x "mb*" -x "Rime*"
- name: Prepare Rime directory for Rabbit
run: |
mkdir -p Rime/
rsync -avm --exclude='.git*' --exclude='*.github*' --exclude='squirrel*' --exclude='weasel*' --exclude='hamster*' --exclude='*.txt' --exclude='xmjd6.zip' --exclude='yong*' --exclude='mb*' --exclude='Rime*' . Rime/
ls -al Rime/
pwd
- name: Get latest release tag
id: get_tag
uses: actions/github-script@v7
with:
script: |
const response = await github.rest.repos.getLatestRelease({
owner: 'amorphobia',
repo: 'rabbit',
});
const tagName = response.data.tag_name;
console.log(`Latest release tag is ${tagName}`);
return tagName;
- name: Fetch tags and generate changelog from last release
id: changelog
uses: actions/github-script@v7
with:
script: |
const lastRelease = await github.rest.repos.getLatestRelease({
owner: context.repo.owner,
repo: context.repo.repo
});
const compare = await github.rest.repos.compareCommits({
owner: context.repo.owner,
repo: context.repo.repo,
base: lastRelease.data.tag_name,
head: 'main'
});
let changelog = '';
compare.data.commits.forEach(commit => {
const message = commit.commit.message.split('\n').join(' ');
const commitLink = `[${commit.sha.substring(0, 7)}](https://github.com/${context.repo.owner}/${context.repo.repo}/commit/${commit.sha})`;
changelog += `- ${commitLink} ${message} \n`;
});
core.setOutput('changelog', changelog);
- name: Set the tag as environment variable
run: echo "RELEASE_TAG=${{ steps.get_tag.outputs.result }}" >> $GITHUB_ENV
- name: Download the release asset
run: |
curl -L -o rabbit-${{ env.RELEASE_TAG }}.zip https://github.com/amorphobia/rabbit/releases/download/${{ env.RELEASE_TAG }}/rabbit-${{ env.RELEASE_TAG }}-x64.zip
- name: Unzip Rabbit
run: |
mkdir -p Rabbit
unzip rabbit-${{ env.RELEASE_TAG }}.zip -d Rabbit
- name: Clean Data
run: |
mkdir -p /tmp/Rabbit_backup
cp Rabbit/Data/punctuation.yaml /tmp/Rabbit_backup/
cp Rabbit/Data/key_bindings.yaml /tmp/Rabbit_backup/
cp Rabbit/Data/default.yaml /tmp/Rabbit_backup/
cp Rabbit/Data/symbols.yaml /tmp/Rabbit_backup/
cp Rime/default.custom.yaml Rabbit/Rime
cp Rime/xmjd6.user.dict.yaml Rabbit/Rime
<<<<<<< HEAD

Check failure on line 94 in .github/workflows/create-release.yml

View workflow run for this annotation

GitHub Actions / .github/workflows/create-release.yml

Invalid workflow file

You have an error in your yaml syntax on line 94
cp Rime/xmjd6.custom.yaml Rabbit/Rime
rm -rf Rabbit/Data/*
rm -f Rime/default.custom.yaml
rm -f Rime/xmjd6.user.dict.yaml
rm -f Rime/xmjd6.custom.yaml
=======
rm -rf Rabbit/Data/*
rm -f Rime/default.custom.yaml
rm -f Rime/xmjd6.user.dict.yaml
>>>>>>> bbcb125c4b727eeca6881c3e163602455245bc0f
cp /tmp/Rabbit_backup/* Rabbit/Data/
rm -rf /tmp/Rabbit_backup
- name: Merge Rime into Rabbit
run: |
cp -r Rime/. Rabbit/Data
zip -r Rabbit-xmjd6.zip Rabbit/
- name: Convert .dict.yaml files to .txt using Bash
run: |
for dict_file in xmjd6.danzi.dict.yaml xmjd6.cizu.dict.yaml xmjd6.zidingyi.dict.yaml xmjd6.fjcy.dict.yaml xmjd6.buchong.dict.yaml xmjd6.yingwen.dict.yaml xmjd6.wxw.dict.yaml
do
txt_file="Rime/$(basename $dict_file .dict.yaml).txt"
awk -F'\t' '
/^[^#]/ {
if ($0 ~ /^---|name:|version:|sort:|\.\.\.$/) next;
if ($1 ~ /^[A-Za-z0-9\s]+$/) {
print $1 " " $2
} else {
print $2 " " $1
}
}' "$dict_file" > "$txt_file"
done
- name: Merge .txt files in specific order, add header, and clean up
run: |
# 创建头文件
header='name=星猫键道6\nkey=`abcedfghijklmnopqrstuvwxyz;\\\nlen=12\nwildcard=~\nbihua=viuoa\ncode_e2=p11+p12+p21+p22+p13+p23\ncode_e3=p11+p21+p31+p13+p23+p33\ncode_a4=p11+p21+p31+n11+p13+p23+p33\n[DATA]'
echo -e "$header" > Rime/xmjd6.header.txt
# 按照指定顺序合并 .txt 文件
cat Rime/xmjd6.danzi.txt \
Rime/xmjd6.cizu.txt \
Rime/xmjd6.zidingyi.txt \
Rime/xmjd6.fjcy.txt \
Rime/xmjd6.buchong.txt \
Rime/xmjd6.yingwen.txt \
Rime/xmjd6.wxw.txt > Rime/xmjd6.body.txt
# 将头文件和主体文件合并到一个中间文件
cat Rime/xmjd6.header.txt Rime/xmjd6.body.txt > mb/xmjd6/tmp_xmjd6.txt
# 将中间文件移动到最终位置
mv mb/xmjd6/tmp_xmjd6.txt mb/xmjd6/xmjd6.txt
# 删除临时文件
rm Rime/xmjd6.header.txt Rime/xmjd6.body.txt
python -c "with open('mb/xmjd6/xmjd6.txt', 'r', encoding='utf-8') as f: data = f.read(); open('mb/xmjd6/xmjd6.txt', 'w', encoding='gb18030', errors='ignore').write(data)"
- name: Zip yong
run: |
mkdir -p .yong
cp yong.ini .yong/
cp -r mb .yong/
zip -r yong-xmjd6.zip .yong
curl -L -o yong-win-2.8.0-0.7z https://yong.dgod.net/download/yong-win-2.8.0-0.7z
7z x yong-win-2.8.0-0.7z -oyong_temp
cp -r .yong yong_temp/yong
cd yong_temp
zip -r ../yong-xmjd6-full.zip yong
rm -rf ../.yong ../yong_temp
- name: Create Release
id: create_release
uses: shogo82148/actions-create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ env.CURRENT_DATE }}
release_name: ${{ env.RELEASE_TITLE }}
body: |
## Changelog
${{ steps.changelog.outputs.changelog }}
## Release Notes
- [如何使用](https://github.com/hugh7007/xmjd6-rere#如何使用)
draft: false
prerelease: false
- name: Upload Rabbit-xmjd6.zip to Release
uses: shogo82148/actions-upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./Rabbit-xmjd6.zip
asset_name: Rabbit-xmjd6.zip
asset_content_type: application/zip
- name: Upload yong-xmjd6.zip to Release
uses: shogo82148/actions-upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./yong-xmjd6.zip
asset_name: yong-xmjd6.zip
asset_content_type: application/zip
- name: Upload yong-xmjd6-full.zip to Release
uses: shogo82148/actions-upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./yong-xmjd6-full.zip
asset_name: yong-xmjd6-full.zip
asset_content_type: application/zip
- name: Upload xmjd6.zip to Release
uses: shogo82148/actions-upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./xmjd6.zip
asset_name: xmjd6.zip
asset_content_type: application/zip