-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
63 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
name: Sync Hitokoto Sentences | ||
|
||
on: | ||
schedule: | ||
- cron: '0 0 * * *' | ||
workflow_dispatch: | ||
push: | ||
branches: | ||
- master | ||
|
||
jobs: | ||
sync: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Get latest tag from sentences-bundle repository | ||
id: get_tag | ||
run: | | ||
TAG=$(git ls-remote --tags https://github.com/hitokoto-osc/sentences-bundle.git | awk '{print $2}' | grep -E '^refs/tags/v[0-9]+\.[0-9]+\.[0-9]+$' | sort -V | tail -n 1 | cut -d '/' -f 3) | ||
echo "Latest tag is $TAG" | ||
echo "TAG=$TAG" >> $GITHUB_OUTPUT | ||
- name: Check npm package version | ||
id: check_version | ||
run: | | ||
PACKAGE_NAME="koishi-plugin-hitokoto-sentences" | ||
TAG=${{ steps.get_tag.outputs.tag }} | ||
VERSIONS=$(npm show $PACKAGE_NAME versions) | ||
if echo "$VERSIONS" | grep -q "$TAG"; then | ||
echo "Version $TAG of $PACKAGE_NAME already exists, exiting." | ||
echo "result=exists" >> $GITHUB_OUTPUT | ||
else | ||
echo "Version $TAG of $PACKAGE_NAME does not exist, proceeding." | ||
fi | ||
- name: Clone sentences-bundle repository | ||
if: steps.check_version.outputs.result != 'exists' | ||
run: | | ||
TAG=${{ steps.get_tag.outputs.tag }} | ||
git clone --branch $TAG --single-branch https://github.com/hitokoto-osc/sentences-bundle.git sentences-bundle | ||
- name: Copy JSON files | ||
if: steps.check_version.outputs.result != 'exists' | ||
run: | | ||
cp sentences-bundle/sentences/*.json data/ | ||
- name: Update package.json version | ||
if: steps.check_version.outputs.result != 'exists' | ||
run: | | ||
TAG=${{ steps.get_tag.outputs.tag }} | ||
PTAG=${TAG#v} # Remove the first 'v' from TAG | ||
sed -i "s/\"version\": \".*\"/\"version\": \"$PTAG\"/" package.json | ||
- name: Publish to npm | ||
if: steps.check_version.outputs.result != 'exists' | ||
run: | | ||
npm publish --dry-run | ||
env: | ||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |