Create Release with Zipped Branch Assets and Date #57
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: Zip main branch files excluding .git and .github | |
run: zip -r xmjd6.zip . -x "*.git*" -x "*.github*" | |
- name: Zip main branch pure files | |
run: | | |
mkdir -p Rime/ | |
rsync -avm --exclude='.git*' --exclude='*.github*' --exclude='squirrel*' --exclude='weasel*' --exclude='hamster*' --exclude='xmjd6.zip' . 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 }}.zip | |
- name: Unzip Rabbit | |
run: | | |
mkdir -p Rabbit | |
unzip rabbit-${{ env.RELEASE_TAG }}.zip -d Rabbit | |
- name: Clean SharedSupport | |
run: | | |
mkdir -p /tmp/Rabbit_backup | |
cp Rabbit/SharedSupport/punctuation.yaml /tmp/Rabbit_backup/ | |
cp Rabbit/SharedSupport/key_bindings.yaml /tmp/Rabbit_backup/ | |
cp Rabbit/SharedSupport/default.yaml /tmp/Rabbit_backup/ | |
rm -rf Rabbit/SharedSupport/* | |
cp /tmp/Rabbit_backup/* Rabbit/SharedSupport/ | |
rm -rf /tmp/Rabbit_backup | |
- name: Merge Rime into Rabbit | |
run: | | |
cp -r Rime/. Rabbit/SharedSupport | |
zip -r Rabbit-xmjd6.zip Rabbit/ | |
- 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#%E5%A6%82%E4%BD%95%E4%BD%BF%E7%94%A8) | |
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 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 |