|
| 1 | +--- |
| 2 | +name: Build Compiled Assets |
| 3 | + |
| 4 | +on: |
| 5 | + workflow_call: |
| 6 | + inputs: |
| 7 | + release: |
| 8 | + type: boolean |
| 9 | + default: false |
| 10 | + description: "Attach artifacts to a release" |
| 11 | + |
| 12 | +jobs: |
| 13 | + build_assets: |
| 14 | + name: Build packages - ${{ matrix.os }} |
| 15 | + runs-on: ${{ matrix.os }} |
| 16 | + strategy: |
| 17 | + fail-fast: true |
| 18 | + matrix: |
| 19 | + include: |
| 20 | + - os: macos-latest |
| 21 | + TARGET: macos |
| 22 | + # currently, wrapt pulls the arm64 version instead of the universal one, so the below is a hack |
| 23 | + CMD_REQS: > |
| 24 | + mkdir -p pip-packages && cd pip-packages && pip wheel --no-cache-dir --no-binary tree_sitter,ijson,charset_normalizer,PyYAML .. && |
| 25 | + rm $(ls | grep wrapt) && pip download wrapt --platform=universal2 --only-binary=:all: && pip install $(ls | grep wrapt) --force-reinstall && cd .. && |
| 26 | + pip install --no-deps --no-index --find-links=pip-packages pip-packages/* |
| 27 | + CMD_BUILD: > |
| 28 | + STATICCODECOV_LIB_PATH=$(find build/ -maxdepth 1 -type d -name 'lib.*' -print -quit | xargs -I {} sh -c "find {} -type f -name 'staticcodecov*' -print -quit | sed 's|^./||'") && |
| 29 | + pyinstaller --add-binary ${STATICCODECOV_LIB_PATH}:. --copy-metadata codecov-cli --hidden-import staticcodecov_languages --target-arch universal2 -F codecov_cli/main.py && |
| 30 | + mv dist/main dist/codecovcli_macos && |
| 31 | + lipo -archs dist/codecovcli_macos | grep 'x86_64 arm64' |
| 32 | + OUT_FILE_NAME: codecovcli_macos |
| 33 | + ASSET_MIME: application/octet-stream |
| 34 | + |
| 35 | + - os: ubuntu-22.04 |
| 36 | + TARGET: ubuntu |
| 37 | + CMD_REQS: > |
| 38 | + pip install -r requirements.txt && pip install . |
| 39 | + CMD_BUILD: > |
| 40 | + STATICCODECOV_LIB_PATH=$(find build/ -maxdepth 1 -type d -name 'lib.*' -print -quit | xargs -I {} sh -c "find {} -type f -name 'staticcodecov*' -print -quit | sed 's|^./||'") && |
| 41 | + pyinstaller --add-binary ${STATICCODECOV_LIB_PATH}:. --copy-metadata codecov-cli --hidden-import staticcodecov_languages -F codecov_cli/main.py && |
| 42 | + cp ./dist/main ./dist/codecovcli_linux |
| 43 | + OUT_FILE_NAME: codecovcli_linux |
| 44 | + ASSET_MIME: application/octet-stream |
| 45 | + |
| 46 | + - os: windows-latest |
| 47 | + TARGET: windows |
| 48 | + CMD_REQS: > |
| 49 | + pip install -r requirements.txt && pip install . |
| 50 | + CMD_BUILD: > |
| 51 | + pyinstaller --add-binary "build\lib.win-amd64-cpython-311\staticcodecov_languages.cp311-win_amd64.pyd;." --copy-metadata codecov-cli --hidden-import staticcodecov_languages -F codecov_cli\main.py && |
| 52 | + Copy-Item -Path ".\dist\main.exe" -Destination ".\dist\codecovcli_windows.exe" |
| 53 | + OUT_FILE_NAME: codecovcli_windows.exe |
| 54 | + ASSET_MIME: application/vnd.microsoft.portable-executable |
| 55 | + |
| 56 | + steps: |
| 57 | + - uses: actions/checkout@v4 |
| 58 | + with: |
| 59 | + submodules: true |
| 60 | + |
| 61 | + - name: Set up Python 3.11 |
| 62 | + uses: actions/setup-python@v3 |
| 63 | + with: |
| 64 | + python-version: "3.11" |
| 65 | + |
| 66 | + - name: Install dependencies |
| 67 | + run: | |
| 68 | + cd codecov-cli |
| 69 | + ${{matrix.CMD_REQS}} |
| 70 | + python setup.py build |
| 71 | +
|
| 72 | + - name: Install pyinstaller |
| 73 | + run: pip install pyinstaller |
| 74 | + |
| 75 | + - name: Build with pyinstaller for ${{matrix.TARGET}} |
| 76 | + run: cd codecov-cli && ${{matrix.CMD_BUILD}} |
| 77 | + |
| 78 | + - name: Upload a Build Artifact |
| 79 | + uses: actions/upload-artifact@v4 |
| 80 | + if: inputs.release == false |
| 81 | + with: |
| 82 | + name: ${{ matrix.OUT_FILE_NAME }} |
| 83 | + path: ./codecov-cli/dist/${{ matrix.OUT_FILE_NAME }} |
| 84 | + |
| 85 | + - name: Get auth token |
| 86 | + if: inputs.release == true |
| 87 | + id: token |
| 88 | + uses: actions/create-github-app-token@df432ceedc7162793a195dd1713ff69aefc7379e # v2.0.6 |
| 89 | + with: |
| 90 | + app-id: ${{ vars.SENTRY_RELEASE_BOT_CLIENT_ID }} |
| 91 | + private-key: ${{ secrets.SENTRY_RELEASE_BOT_PRIVATE_KEY }} |
| 92 | + |
| 93 | + - name: Upload Release Asset |
| 94 | + if: inputs.release == true |
| 95 | + id: upload-release-asset |
| 96 | + uses: svenstaro/upload-release-action@v2 |
| 97 | + with: |
| 98 | + repo_token: ${{ steps.token.outputs.token }} |
| 99 | + file: ./codecov-cli/dist/${{ matrix.OUT_FILE_NAME }} |
| 100 | + asset_name: ${{ matrix.OUT_FILE_NAME }} |
| 101 | + tag: ${{ github.ref }} |
| 102 | + overwrite: true |
| 103 | + |
| 104 | + build_assets_alpine_arm: |
| 105 | + name: Build assets - Alpine and ARM |
| 106 | + runs-on: ubuntu-latest |
| 107 | + strategy: |
| 108 | + matrix: |
| 109 | + include: |
| 110 | + - distro: "python:3.11-alpine3.18" |
| 111 | + arch: arm64 |
| 112 | + distro_name: alpine |
| 113 | + - distro: "python:3.11-alpine3.18" |
| 114 | + arch: x86_64 |
| 115 | + distro_name: alpine |
| 116 | + - distro: "python:3.11-bullseye" |
| 117 | + arch: arm64 |
| 118 | + distro_name: linux |
| 119 | + |
| 120 | + steps: |
| 121 | + - uses: actions/checkout@v4 |
| 122 | + with: |
| 123 | + submodules: true |
| 124 | + |
| 125 | + - name: Set up QEMU |
| 126 | + uses: docker/setup-qemu-action@v1 |
| 127 | + with: |
| 128 | + platforms: ${{ matrix.arch }} |
| 129 | + |
| 130 | + - name: Run in Docker |
| 131 | + run: | |
| 132 | + docker run \ |
| 133 | + --rm \ |
| 134 | + -v $(pwd):/${{ github.workspace }} \ |
| 135 | + -w ${{ github.workspace }} \ |
| 136 | + --platform linux/${{ matrix.arch }} \ |
| 137 | + ${{ matrix.distro }} \ |
| 138 | + ./codecov-cli/scripts/build_${{ matrix.distro_name }}_arm.sh ${{ matrix.distro_name }}_${{ matrix.arch }} |
| 139 | +
|
| 140 | + - name: Upload a Build Artifact |
| 141 | + uses: actions/upload-artifact@v4 |
| 142 | + if: inputs.release == false |
| 143 | + with: |
| 144 | + name: codecovcli_${{ matrix.distro_name }}_${{ matrix.arch }} |
| 145 | + path: ./codecov-cli/dist/codecovcli_${{ matrix.distro_name }}_${{ matrix.arch }} |
| 146 | + |
| 147 | + - name: Get auth token |
| 148 | + if: inputs.release == true |
| 149 | + id: token |
| 150 | + uses: actions/create-github-app-token@df432ceedc7162793a195dd1713ff69aefc7379e # v2.0.6 |
| 151 | + with: |
| 152 | + app-id: ${{ vars.SENTRY_RELEASE_BOT_CLIENT_ID }} |
| 153 | + private-key: ${{ secrets.SENTRY_RELEASE_BOT_PRIVATE_KEY }} |
| 154 | + |
| 155 | + - name: Upload Release Asset |
| 156 | + if: inputs.release == true |
| 157 | + id: upload-release-asset |
| 158 | + uses: svenstaro/upload-release-action@v2 |
| 159 | + with: |
| 160 | + repo_token: ${{ steps.token.outputs.token }} |
| 161 | + file: ./codecov-cli/dist/codecovcli_${{ matrix.distro_name }}_${{ matrix.arch }} |
| 162 | + asset_name: codecovcli_${{ matrix.distro_name }}_${{ matrix.arch }} |
| 163 | + tag: ${{ github.ref }} |
| 164 | + overwrite: true |
0 commit comments