| 1 | name: Bazel |
| 2 | |
| 3 | on: |
| 4 | push: |
| 5 | branches: [master] |
| 6 | pull_request: |
| 7 | branches: [master] |
| 8 | |
| 9 | concurrency: |
| 10 | group: ${{ github.workflow }}-${{ github.ref }} |
| 11 | cancel-in-progress: true |
| 12 | |
| 13 | jobs: |
| 14 | resource-package: |
| 15 | permissions: |
| 16 | contents: read |
| 17 | runs-on: ubuntu-latest |
| 18 | |
| 19 | steps: |
| 20 | - uses: actions/checkout@v5 |
| 21 | with: |
| 22 | fetch-depth: 0 |
| 23 | - name: Compute version |
| 24 | id: version |
| 25 | shell: bash |
| 26 | run: | |
| 27 | VERSION=$(bash scripts/compute-version.sh) |
| 28 | echo "VERSION=$VERSION" >> "$GITHUB_ENV" |
| 29 | echo "version=$VERSION" >> "$GITHUB_OUTPUT" |
| 30 | echo "Computed version: $VERSION" |
| 31 | - uses: bazel-contrib/[email protected] |
| 32 | with: |
| 33 | bazelisk-cache: true |
| 34 | repository-cache: true |
| 35 | - name: Set up Python |
| 36 | uses: actions/setup-python@v6 |
| 37 | with: |
| 38 | python-version: "3.12" |
| 39 | - name: Configure BuildBuddy |
| 40 | if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository |
| 41 | shell: bash |
| 42 | env: |
| 43 | BUILDBUDDY_API_KEY: ${{ secrets.BUILDBUDDY_API_KEY }} |
| 44 | run: | |
| 45 | if [ -n "${BUILDBUDDY_API_KEY}" ]; then |
| 46 | { |
| 47 | echo "build --config=buildbuddy" |
| 48 | echo "build --remote_header=x-buildbuddy-api-key=${BUILDBUDDY_API_KEY}" |
| 49 | echo "build --bes_header=x-buildbuddy-api-key=${BUILDBUDDY_API_KEY}" |
| 50 | } >> .bazelrc.user |
| 51 | echo "BuildBuddy enabled." |
| 52 | else |
| 53 | echo "BUILDBUDDY_API_KEY not set; skipping BuildBuddy config." |
| 54 | fi |
| 55 | - name: Build resource package |
| 56 | shell: bash |
| 57 | env: |
| 58 | MSYS_NO_PATHCONV: 1 |
| 59 | run: | |
| 60 | bazel build \ |
| 61 | --workspace_status_command=./scripts/bazel-workspace-status.sh \ |
| 62 | //data:opencc_resources_zip |
| 63 | - name: Stage resource package |
| 64 | shell: bash |
| 65 | run: | |
| 66 | mkdir -p dist |
| 67 | cp bazel-bin/data/opencc-resources.zip "dist/opencc-${VERSION}-resources.zip" |
| 68 | unzip -l "dist/opencc-${VERSION}-resources.zip" |
| 69 | - name: Upload resource package |
| 70 | uses: actions/upload-artifact@v7 |
| 71 | with: |
| 72 | path: dist/opencc-${{ env.VERSION }}-resources.zip |
| 73 | archive: false |
| 74 | if-no-files-found: error |
| 75 | |
| 76 | build-and-test: |
| 77 | permissions: |
| 78 | contents: read |
| 79 | runs-on: ${{ matrix.os }} |
| 80 | strategy: |
| 81 | matrix: |
| 82 | os: [ubuntu-latest, macos-latest, windows-2025-vs2026] |
| 83 | |
| 84 | steps: |
| 85 | - uses: actions/checkout@v5 |
| 86 | with: |
| 87 | fetch-depth: 0 |
| 88 | - name: Best-effort Defender exclusions |
| 89 | if: runner.os == 'Windows' |
| 90 | shell: pwsh |
| 91 | continue-on-error: true |
| 92 | run: | |
| 93 | Add-MpPreference -ExclusionPath "$env:GITHUB_WORKSPACE" ` |
| 94 | -ExclusionProcess "bazel.exe","bazelisk.exe","python.exe","cl.exe","link.exe" |
| 95 | - name: Compute version |
| 96 | id: version |
| 97 | shell: bash |
| 98 | run: | |
| 99 | VERSION=$(bash scripts/compute-version.sh) |
| 100 | echo "VERSION=$VERSION" >> "$GITHUB_ENV" |
| 101 | echo "version=$VERSION" >> "$GITHUB_OUTPUT" |
| 102 | echo "Computed version: $VERSION" |
| 103 | - uses: bazel-contrib/[email protected] |
| 104 | with: |
| 105 | bazelisk-cache: true |
| 106 | repository-cache: true |
| 107 | - name: Set up Python |
| 108 | uses: actions/setup-python@v6 |
| 109 | with: |
| 110 | python-version: "3.12" |
| 111 | - name: Configure BuildBuddy |
| 112 | if: (github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository) && runner.os != 'Windows' |
| 113 | shell: bash |
| 114 | env: |
| 115 | BUILDBUDDY_API_KEY: ${{ secrets.BUILDBUDDY_API_KEY }} |
| 116 | run: | |
| 117 | if [ -n "${BUILDBUDDY_API_KEY}" ]; then |
| 118 | { |
| 119 | echo "build --config=buildbuddy" |
| 120 | echo "build --remote_header=x-buildbuddy-api-key=${BUILDBUDDY_API_KEY}" |
| 121 | echo "build --bes_header=x-buildbuddy-api-key=${BUILDBUDDY_API_KEY}" |
| 122 | } >> .bazelrc.user |
| 123 | echo "BuildBuddy enabled." |
| 124 | else |
| 125 | echo "BUILDBUDDY_API_KEY not set; skipping BuildBuddy config." |
| 126 | fi |
| 127 | - name: Build |
| 128 | if: runner.os == 'Linux' || runner.os == 'macOS' |
| 129 | shell: bash |
| 130 | env: |
| 131 | MSYS_NO_PATHCONV: 1 |
| 132 | run: bazel build //:opencc //src/tools/... //plugins/... //node/... |
| 133 | - name: Test |
| 134 | shell: bash |
| 135 | env: |
| 136 | MSYS_NO_PATHCONV: 1 |
| 137 | run: | |
| 138 | set +e |
| 139 | bazel test --show_timestamps --test_output=all --nocache_test_results --skip_incompatible_explicit_targets //src/... //data/... //test/... //python/... //plugins/... //node/test:node_test |
| 140 | status=$? |
| 141 | bash scripts/collect_bazel_testlogs.sh bazel-testlogs-artifact |
| 142 | if [ "$status" -ne 0 ]; then |
| 143 | echo "Bazel test failed with exit code ${status}." |
| 144 | testlogs_dir="$(bazel info bazel-testlogs 2>/dev/null)" |
| 145 | echo "Bazel testlogs dir: ${testlogs_dir}" |
| 146 | echo "Failing test logs:" |
| 147 | find "${testlogs_dir}" -name test.log -print |
| 148 | while IFS= read -r log; do |
| 149 | echo "===== ${log#"${testlogs_dir}/"} =====" |
| 150 | sed -n '1,240p' "${log}" |
| 151 | done < <(find "${testlogs_dir}" -name test.log -print | sort) |
| 152 | fi |
| 153 | exit "$status" |
| 154 | - name: upload artifacts |
| 155 | if: ${{ always() }} |
| 156 | uses: actions/upload-artifact@v7 |
| 157 | with: |
| 158 | name: opencc-${{ env.VERSION }}-bazel-${{ matrix.os }} |
| 159 | path: | |
| 160 | bazel-testlogs-artifact/** |