diff --git a/.github/workflows/pr.yml b/.github/workflows/build_pr.yml similarity index 100% rename from .github/workflows/pr.yml rename to .github/workflows/build_pr.yml diff --git a/.github/workflows/release.yml b/.github/workflows/build_release.yml similarity index 82% rename from .github/workflows/release.yml rename to .github/workflows/build_release.yml index e4acfa1..264cba7 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/build_release.yml @@ -1,10 +1,27 @@ +# This workflow is used to create a (pre-)release build of the OpenList frontend. +# +# This will: +# +# - Update the `package.json` version to the specified version (when triggered +# by `workflow_dispatch`), commit the changes and tag it. +# - Upload the release assets to GitHub. +# - Publish the package to npm. +# +# # Usage +# +# This workflow can be triggered by: +# +# - Pushing a tag that matches the pattern `v[0-9]+.[0-9]+.[0-9]+*` (semver format). +# - Manually via the GitHub Actions UI with a version input. +# +# To create (pre-)release builds, we recommend that you use the `workflow_dispatch`. + name: Release Build on: push: tags: - - "v*.*.*" - - "!v*.*.*-*" + - "v[0-9]+.[0-9]+.[0-9]+*" workflow_dispatch: inputs: version: @@ -54,8 +71,8 @@ jobs: if: github.event_name == 'workflow_dispatch' uses: crazy-max/ghaction-import-gpg@v6 with: - gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }} - passphrase: ${{ secrets.GPG_PASSPHRASE }} + gpg_private_key: ${{ secrets.BOT_GPG_PRIVATE_KEY }} + passphrase: ${{ secrets.BOT_GPG_PASSPHRASE }} git_user_signingkey: true git_commit_gpgsign: true git_tag_gpgsign: true @@ -115,18 +132,6 @@ jobs: CROWDIN_PROJECT_ID: ${{ secrets.CROWDIN_PROJECT_ID }} CROWDIN_PERSONAL_TOKEN: ${{ secrets.CROWDIN_PERSONAL_TOKEN }} - - name: Publish npm - run: | - echo "//registry.npmjs.org/:_authToken=${NODE_AUTH_TOKEN}" > ~/.npmrc - if [ -z "${{ secrets.NPM_TOKEN }}" ]; then - echo "NPM_TOKEN not set, do dry run" - pnpm publish --dry-run --no-git-checks --access public - else - pnpm publish --no-git-checks --access public - fi - env: - NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} - - name: Upload Release Assets run: | # Delete local tag, or gh cli will complain about it. @@ -140,5 +145,26 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Publish npm + run: | + echo "//registry.npmjs.org/:_authToken=${NODE_AUTH_TOKEN}" > ~/.npmrc + # Delete the generated dist tarball + rm -f dist/openlist-frontend-dist-v*.tar.gz + + if ! jq -e '.name and .version' package.json > /dev/null; then + echo "Error: Invalid package.json" + exit 1 + fi + + if [ -z "${{ secrets.NPM_TOKEN }}" ]; then + echo "NPM_TOKEN not set, performing dry run" + pnpm publish --dry-run --no-git-checks --access public + else + echo "Publishing to npm..." + pnpm publish --no-git-checks --access public + fi + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} + permissions: contents: write diff --git a/.github/workflows/pre-release.yml b/.github/workflows/build_rolling.yml similarity index 77% rename from .github/workflows/pre-release.yml rename to .github/workflows/build_rolling.yml index 6ad9932..dfda529 100644 --- a/.github/workflows/pre-release.yml +++ b/.github/workflows/build_rolling.yml @@ -1,11 +1,17 @@ -name: Pre Release Build +# This workflow builds a rolling version of the OpenList frontend and publishes it on GitHub. +# +# This will: +# +# - Upload the release assets to GitHub (always git tagged `rolling`). +# +# This workflow can be triggered on pushes to the `main` branch, or manually via the GitHub Actions UI. + +name: Rolling Build on: push: branches: - main - tags: - - "v*.*.*-*" workflow_dispatch: inputs: draft: @@ -15,8 +21,8 @@ on: type: boolean jobs: - pre-release: - name: Pre Release + rolling: + name: Rolling Build runs-on: ubuntu-latest steps: - name: Checkout code @@ -48,14 +54,9 @@ jobs: - name: Read version and determine tag name id: version run: | - if [[ "${{ github.ref }}" == refs/tags/* ]]; then - echo "version=${{ github.ref_name }}" >> $GITHUB_OUTPUT - echo "tag_name=${{ github.ref_name }}" >> $GITHUB_OUTPUT - else - version=$(cat dist/VERSION) - echo "version=$version" >> $GITHUB_OUTPUT - echo "tag_name=rolling" >> $GITHUB_OUTPUT - fi + version=$(cat dist/VERSION) + echo "version=$version" >> $GITHUB_OUTPUT + echo "tag_name=rolling" >> $GITHUB_OUTPUT - name: Remove the existing pre-release run: gh release delete ${{ steps.version.outputs.tag_name }} --cleanup-tag --yes || true @@ -68,7 +69,7 @@ jobs: --title "Pre-release ${{ steps.version.outputs.version }}" \ --notes "Pre-release build for ${{ steps.version.outputs.version }}
This is a development build and not intended for production use." \ --prerelease \ - --draft=${{ github.event_name == 'workflow_dispatch' && inputs.draft || false }} \ + --draft=${{ github.event_name == 'workflow_dispatch' && github.event.inputs.draft || false }} \ ${{ steps.version.outputs.tag_name }} \ dist/openlist-frontend-dist-v*-*.tar.gz env: diff --git a/.github/workflows/crowdin-upload.yml b/.github/workflows/crowdin-upload.yml deleted file mode 100644 index 70f7fd9..0000000 --- a/.github/workflows/crowdin-upload.yml +++ /dev/null @@ -1,39 +0,0 @@ -name: Crowdin Upload - -on: - push: - branches: [main] - paths: - - "src/lang/en/**" - -jobs: - crowdin-upload: - name: Upload en lang source file to Crowdin - runs-on: ubuntu-latest - - steps: - - name: Checkout code - uses: actions/checkout@v4 - with: - fetch-depth: 0 - submodules: recursive - - - name: Setup Node - uses: actions/setup-node@v4 - with: - node-version: "18" - registry-url: "https://registry.npmjs.org" - - - name: Install pnpm - uses: pnpm/action-setup@v4 - with: - run_install: false - - - name: Install dependencies - run: pnpm install - - - name: Upload sources to Crowdin - run: pnpm run crowdin:upload - env: - CROWDIN_PROJECT_ID: ${{ secrets.CROWDIN_PROJECT_ID }} - CROWDIN_PERSONAL_TOKEN: ${{ secrets.CROWDIN_PERSONAL_TOKEN }} diff --git a/.github/workflows/i18n_sync.yml b/.github/workflows/i18n_sync.yml new file mode 100644 index 0000000..9500f95 --- /dev/null +++ b/.github/workflows/i18n_sync.yml @@ -0,0 +1,105 @@ +name: Sync i18n files + +on: + schedule: + - cron: "0 12 * * *" + push: + branches: [main] + paths: + - "src/lang/en/**" + pull_request: + paths: + - ".github/workflows/i18n*.yml" + workflow_dispatch: + +jobs: + sync_i18n: + name: Generate and i18n files + runs-on: ubuntu-latest + steps: + - name: Setup go + uses: actions/setup-go@v5 + with: + go-version: "1.21" + + - name: Checkout frontend codes + uses: actions/checkout@v4 + with: + fetch-depth: 0 + submodules: recursive + + - name: Checkout backend codes + uses: actions/checkout@v4 + with: + repository: ${{ vars.SYNC_LANG_ENV_BACKEND_REPOSITORY || 'OpenListTeam/OpenList' }} + path: backend + fetch-depth: 0 + submodules: recursive + + - name: Generate and update lang files + run: | + cd backend + go run ./main.go lang --frontend-path ../ + cd .. + + - name: Check for changes and stage + id: verify-changed-files + run: | + cp -f ./backend/lang/*.json ./src/lang/en/ 2>/dev/null || : + if [ -n "$(git status --porcelain)" ]; then + git add src/lang/en/*.json + echo "changed=true" >> $GITHUB_OUTPUT + else + echo "changed=false" >> $GITHUB_OUTPUT + fi + + - name: Import GPG key + if: steps.verify-changed-files.outputs.changed == 'true' + uses: crazy-max/ghaction-import-gpg@v6 + with: + gpg_private_key: ${{ secrets.BOT_GPG_PRIVATE_KEY }} + passphrase: ${{ secrets.BOT_GPG_PASSPHRASE }} + git_config_global: true + git_user_signingkey: true + git_commit_gpgsign: true + git_tag_gpgsign: true + + - name: Setup CI Bot + if: steps.verify-changed-files.outputs.changed == 'true' + run: | + git config --global user.name "The OpenList Bot" + git config --global user.email "bot@openlist.team" + + - name: Commit the changes + if: steps.verify-changed-files.outputs.changed == 'true' + run: | + git commit -S -m "chore: auto update i18n file" + # Skip pushing if triggered by a pull request + if [ "${{ github.event_name }}" != "pull_request" ]; then + git push + fi + + - name: Setup Node + if: steps.verify-changed-files.outputs.changed == 'true' + uses: actions/setup-node@v4 + with: + node-version: "18" + registry-url: "https://registry.npmjs.org" + + - name: Install pnpm + if: steps.verify-changed-files.outputs.changed == 'true' + uses: pnpm/action-setup@v4 + with: + # version: 9.9.0 + run_install: false + + - name: Install dependencies + run: pnpm install + + - name: Sync to Crowdin + if: steps.verify-changed-files.outputs.changed == 'true' + run: | + pnpm crowdin:upload + env: + CROWDIN_PROJECT_ID: ${{ secrets.CROWDIN_PROJECT_ID }} + CROWDIN_PERSONAL_TOKEN: ${{ secrets.CROWDIN_PERSONAL_TOKEN }} diff --git a/.gitignore b/.gitignore index 4799131..35b0b2e 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ dist !/src/lang/en/ .DS_Store .idea +.test \ No newline at end of file