| 1 | name: Resource Package Release |
| 2 | |
| 3 | on: |
| 4 | workflow_dispatch: |
| 5 | inputs: |
| 6 | version: |
| 7 | description: "Release version or tag, for example 1.4.0 or ver.1.4.0" |
| 8 | required: false |
| 9 | push: |
| 10 | tags: |
| 11 | - "ver.*" |
| 12 | |
| 13 | concurrency: |
| 14 | group: ${{ github.workflow }}-${{ github.ref }} |
| 15 | cancel-in-progress: true |
| 16 | |
| 17 | jobs: |
| 18 | build-resource-package: |
| 19 | runs-on: ubuntu-24.04 |
| 20 | permissions: |
| 21 | contents: write |
| 22 | steps: |
| 23 | - uses: actions/checkout@v5 |
| 24 | with: |
| 25 | fetch-depth: 0 |
| 26 | |
| 27 | - name: Resolve version |
| 28 | id: version |
| 29 | shell: bash |
| 30 | env: |
| 31 | INPUT_VERSION: ${{ github.event.inputs.version }} |
| 32 | GIT_REF_TYPE: ${{ github.ref_type }} |
| 33 | GIT_REF_NAME: ${{ github.ref_name }} |
| 34 | run: | |
| 35 | value="${INPUT_VERSION:-}" |
| 36 | if [ -z "$value" ] && [ "${GIT_REF_TYPE:-}" = "tag" ]; then |
| 37 | value="${GIT_REF_NAME}" |
| 38 | fi |
| 39 | if [ -z "$value" ]; then |
| 40 | value="$(bash scripts/compute-version.sh)" |
| 41 | fi |
| 42 | value="${value#ver.}" |
| 43 | if [[ "$value" != v* ]]; then |
| 44 | value="v${value}" |
| 45 | fi |
| 46 | echo "value=$value" >> "$GITHUB_OUTPUT" |
| 47 | echo "VERSION=$value" >> "$GITHUB_ENV" |
| 48 | |
| 49 | - uses: bazel-contrib/[email protected] |
| 50 | with: |
| 51 | bazelisk-cache: true |
| 52 | repository-cache: true |
| 53 | |
| 54 | - name: Set up Python |
| 55 | uses: actions/setup-python@v6 |
| 56 | with: |
| 57 | python-version: "3.12" |
| 58 | |
| 59 | - name: Configure BuildBuddy |
| 60 | shell: bash |
| 61 | env: |
| 62 | BUILDBUDDY_API_KEY: ${{ secrets.BUILDBUDDY_API_KEY }} |
| 63 | run: | |
| 64 | if [ -n "${BUILDBUDDY_API_KEY}" ]; then |
| 65 | { |
| 66 | echo "build --config=buildbuddy" |
| 67 | echo "build --remote_header=x-buildbuddy-api-key=${BUILDBUDDY_API_KEY}" |
| 68 | echo "build --bes_header=x-buildbuddy-api-key=${BUILDBUDDY_API_KEY}" |
| 69 | } >> .bazelrc.user |
| 70 | echo "BuildBuddy enabled." |
| 71 | else |
| 72 | echo "BUILDBUDDY_API_KEY not set; skipping BuildBuddy config." |
| 73 | fi |
| 74 | |
| 75 | - name: Build resource package |
| 76 | shell: bash |
| 77 | env: |
| 78 | MSYS_NO_PATHCONV: 1 |
| 79 | run: | |
| 80 | bazel build \ |
| 81 | --workspace_status_command=./scripts/bazel-workspace-status.sh \ |
| 82 | //data:opencc_resources_zip |
| 83 | |
| 84 | - name: Stage resource package |
| 85 | shell: bash |
| 86 | run: | |
| 87 | mkdir -p dist |
| 88 | cp bazel-bin/data/opencc-resources.zip "dist/opencc-${VERSION}-resources.zip" |
| 89 | unzip -l "dist/opencc-${VERSION}-resources.zip" |
| 90 | |
| 91 | - name: Upload resource package artifact |
| 92 | uses: actions/upload-artifact@v7 |
| 93 | with: |
| 94 | name: opencc-resources-${{ steps.version.outputs.value }} |
| 95 | path: dist/opencc-${{ steps.version.outputs.value }}-resources.zip |
| 96 | archive: false |
| 97 | if-no-files-found: error |
| 98 | |
| 99 | - name: Upload assets to existing GitHub release |
| 100 | if: startsWith(github.ref, 'refs/tags/') |
| 101 | env: |
| 102 | GH_TOKEN: ${{ github.token }} |
| 103 | run: | |
| 104 | tag="${{ github.ref_name }}" |
| 105 | for i in $(seq 1 30); do |
| 106 | gh release view "$tag" --json isDraft > /dev/null 2>&1 && break |
| 107 | echo "Waiting for release $tag to be created ($i/30)..." |
| 108 | sleep 10 |
| 109 | done |
| 110 | gh release upload "$tag" \ |
| 111 | "dist/opencc-${VERSION}-resources.zip" \ |
| 112 | --clobber |