Skip to content

Commit

Permalink
ci: add sync workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
MaikoTan committed Dec 5, 2023
1 parent 617c51d commit 2c92b45
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions .github/workflows/sync.yml
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 }}

0 comments on commit 2c92b45

Please sign in to comment.