Sync Hitokoto Sentences #170
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: Sync Hitokoto Sentences | |
on: | |
schedule: | |
- cron: '0 0 * * *' | |
workflow_dispatch: | |
inputs: | |
version: | |
description: 'The version of the package to be published' | |
required: true | |
push: | |
branches: | |
- master | |
jobs: | |
check: | |
runs-on: ubuntu-latest | |
outputs: | |
tag: ${{ steps.get_tag.outputs.tag }} | |
result: ${{ steps.check_version.outputs.result }} | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Get latest tag from sentences-bundle repository | |
if: github.event_name != 'workflow_dispatch' | |
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 | |
if: github.event_name != 'workflow_dispatch' | |
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#v}"; 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 | |
sync: | |
runs-on: ubuntu-latest | |
needs: [check] | |
if: needs.check.outputs.result != 'exists' || github.event_name == 'workflow_dispatch' | |
steps: | |
- name: Checkout hitokoto-sentences repository | |
uses: actions/checkout@v4 | |
- name: Clone sentences-bundle repository | |
uses: actions/checkout@v4 | |
with: | |
repository: hitokoto-osc/sentences-bundle | |
ref: ${{ needs.check.outputs.tag }} | |
path: sentences-bundle | |
- name: Copy JSON files | |
run: | | |
cp sentences-bundle/sentences/*.json data/ | |
- name: Update package.json version | |
run: | | |
TAG=${{ needs.check.outputs.tag || github.event.inputs.version }} | |
PTAG=${TAG#v} # Remove the first 'v' from TAG | |
sed -i "s/\"version\": \".*\"/\"version\": \"$PTAG\"/" package.json | |
- name: Build | |
run: | | |
yarn | |
yarn add -D koishi | |
yarn build | |
- name: Set npm token | |
run: | | |
echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > ~/.npmrc | |
- name: Publish to npm | |
run: | | |
npm publish |