summaryrefslogtreecommitdiffstats
path: root/.github/workflows/release.yml
blob: 1d435bed86ddd83615d7f9ac7b5ced44f8bbbb4d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
name: Release

on:
  push:
    # Also run on pushes to the main branch so that we can keep the llvm and sccache
    # caches filled in a scope available to everyone
    branches:
      - master
    paths-ignore:
      - "docs/**"
      - "LICENSES/**"
      - "LICENSE"
      - "CONTRIBUTING.md"
      - "README.md"
    tags:
      - "v*"

jobs:
  release:
    strategy:
      matrix:
        os: [linux, macos, windows]
        config: [releaseWithDebugInfo]
        platform: [x86_64, aarch64]
        test-category: [smoke]
        include:
          - { os: linux, runs-on: ubuntu-20.04, compiler: gcc }
          - { os: windows, runs-on: windows-latest, compiler: cl }
          - { os: macos, runs-on: macos-latest, compiler: clang }

          - { build-slang-llvm: false }
          - { os: linux, platform: x86_64, build-slang-llvm: true }
          - { os: windows, platform: x86_64, build-slang-llvm: true }
          - { os: macos, platform: aarch64, build-slang-llvm: true }
      fail-fast: false
    runs-on: ${{ matrix.runs-on }}
    container: ${{ matrix.image || '' }}

    defaults:
      run:
        shell: bash

    steps:
      - uses: actions/checkout@v4
        with:
          submodules: "recursive"
          fetch-depth: "0"
      - name: Setup
        uses: ./.github/actions/common-setup
        with:
          os: ${{matrix.os}}
          compiler: ${{matrix.compiler}}
          platform: ${{matrix.platform}}
          config: ${{matrix.config}}
          build-llvm: ${{matrix.build-slang-llvm}}

      - name: Build slang generators
        run: |
          cmake --workflow --preset generators --fresh
          mkdir build-platform-generators
          cmake --install build --config Release --component generators --prefix build-platform-generators

      - name: Change dev tools to host arch (windows)
        uses: ilammy/msvc-dev-cmd@v1
        with:
          arch: ${{matrix.platform == 'aarch64' && 'amd64_arm64' || 'amd64'}}
          sdk: "10.0.19041.0"

      - name: Change dev tools to host arch (linux and macos)
        run: |
          if [[ "${{matrix.os}}" == linux* && "${{matrix.platform}}" == "aarch64" && "$(uname -m)" != "aarch64" ]]; then
            export CC=aarch64-linux-gnu-gcc
            export CXX=aarch64-linux-gnu-g++
          fi
          CMAKE_OSX_ARCHITECTURES="${{matrix.platform}}"
          CMAKE_OSX_ARCHITECTURES=${CMAKE_OSX_ARCHITECTURES//aarch64/arm64}

          echo "CC=$CC" >> "$GITHUB_ENV"
          echo "CXX=$CXX" >> "$GITHUB_ENV"
          echo "CMAKE_OSX_ARCHITECTURES=$CMAKE_OSX_ARCHITECTURES" >> "$GITHUB_ENV"

      - name: Build Slang
        run: |
          if [[ "${{ matrix.os }}" == "windows" && "${{ matrix.config }}" != "release" && "${{ matrix.config }}" != "releaseWithDebugInfo" ]]; then
              echo "Please see ci.yml for the steps to make non-release builds work on Windows" >&2
              exit 1
          fi

          cmake --preset default --fresh \
            -DSLANG_GENERATORS_PATH=build-platform-generators/bin \
            -DSLANG_ENABLE_EXAMPLES=OFF \
            "-DSLANG_SLANG_LLVM_FLAVOR=$(
              [[ "${{matrix.build-slang-llvm}}" = "true" ]] && echo "USE_SYSTEM_LLVM" || echo "DISABLE")"

          cmake --build --preset "${{matrix.config}}"

      - name: Sign and notarize binaries
        if: matrix.os == 'macos' && startsWith(github.ref, 'refs/tags/v')
        id: notarize
        env:
          BUILD_CERTIFICATE_BASE64: ${{ secrets.BUILD_CERTIFICATE_BASE64 }}
          P12_PASSWORD: ${{ secrets.P12_PASSWORD }}
          KEYCHAIN_PASSWORD: ${{ secrets.KEYCHAIN_PASSWORD }}
          IDENTITY_ID: d6ada82a113e4204aaad914e1013e9548ffd30d0
          AC_PASSWORD: ${{secrets.APPLE_ID_PASSWORD}}
          AC_PROVIDER: ${{secrets.APPLE_ID_PPOVIDER}}
          AC_USERNAME: ${{secrets.APPLE_ID_USERNAME}}
        run: |
          brew install Bearer/tap/gon
          security find-identity -v
          brew install coreutils
          # create variables
          CERTIFICATE_PATH=$RUNNER_TEMP/build_certificate.p12
          KEYCHAIN_PATH=$RUNNER_TEMP/app-signing.keychain-db
          # import certificate and provisioning profile from secrets
          echo -n "$BUILD_CERTIFICATE_BASE64" | base64 --decode --output "$CERTIFICATE_PATH"
          # create temporary keychain
          security create-keychain -p "$KEYCHAIN_PASSWORD" "$KEYCHAIN_PATH"
          security set-keychain-settings -lut 21600 "$KEYCHAIN_PATH"
          security unlock-keychain -p "$KEYCHAIN_PASSWORD" "$KEYCHAIN_PATH"
          # import certificate to keychain
          security import "$CERTIFICATE_PATH" -P "$P12_PASSWORD" -A -t cert -f pkcs12 -k "$KEYCHAIN_PATH"
          security list-keychain -d user -s "$KEYCHAIN_PATH"
          security set-key-partition-list -S apple-tool:,apple:,codesign: -s -k "${KEYCHAIN_PASSWORD}" "$KEYCHAIN_PATH"

          binaries=(
            "${lib_dir}/libslang.dylib"
            "${lib_dir}/libslang-rt.dylib"
            "${lib_dir}/libslang-glslang.dylib"
            "${lib_dir}/libslang-llvm.dylib"
            "${lib_dir}/libgfx.dylib"
            "${bin_dir}/slangd"
            "${bin_dir}/slangc"
          )

          # Sign main binaries
          for b in "${binaries[@]}"; do
            if [[ -f "$b" ]]; then
              echo "Signing binary '$b'..."
              /usr/bin/codesign --force --options runtime -s "${IDENTITY_ID}" "$b" -v
              7z a "slang-macos-dist.zip" "$b"
            fi
          done

          timeout 1000 gon ./extras/macos-notarize.json
          cp slang-macos-dist.zip "slang-macos-dist-${{matrix.platform}}.zip"
          echo "SLANG_NOTARIZED_DIST=slang-macos-dist-${{matrix.platform}}.zip" >> "$GITHUB_OUTPUT"

      - name: Package Slang
        id: package
        run: |
          # Package main binaries
          cpack --preset "$config" -G ZIP
          cpack --preset "$config" -G TGZ
          # Package debug info
          cpack --preset "$config-debug-info" -G ZIP
          cpack --preset "$config-debug-info" -G TGZ

          triggering_ref=${{ github.ref_name }}
          base=slang-${triggering_ref#v}-${{matrix.os}}-${{matrix.platform}}

          # Move main packages
          mv "$(pwd)/build/dist-${config}/slang.zip" "${base}.zip"
          echo "SLANG_BINARY_ARCHIVE_ZIP=${base}.zip" >> "$GITHUB_OUTPUT"
          mv "$(pwd)/build/dist-${config}/slang.tar.gz" "${base}.tar.gz"
          echo "SLANG_BINARY_ARCHIVE_TAR=${base}.tar.gz" >> "$GITHUB_OUTPUT"

          # Move debug info packages
          mv "$(pwd)/build/dist-${config}-debug-info/slang-debug-info.zip" "${base}-debug-info.zip"
          echo "SLANG_DEBUG_INFO_ARCHIVE_ZIP=${base}-debug-info.zip" >> "$GITHUB_OUTPUT"
          mv "$(pwd)/build/dist-${config}-debug-info/slang-debug-info.tar.gz" "${base}-debug-info.tar.gz"
          echo "SLANG_DEBUG_INFO_ARCHIVE_TAR=${base}-debug-info.tar.gz" >> "$GITHUB_OUTPUT"

          # For some reason, the binaries packed by cpack for macos is modified
          # by cpack and considered damanged by macos. For now we workaround this
          # by repacking all the binaries into the release package.
          if [[ "${{ matrix.os }}"  == "macos" ]]; then
            mkdir ./ttmp
            unzip "${base}.zip" -d ./ttmp

            # Copy only existing files from build directory
            find ./ttmp/{bin,lib} -type f | while read -r file; do
              src_file="build/$cmake_config/${file#./ttmp/}"
              if [ -f "$src_file" ]; then
                cp "$src_file" "$file"
              fi
            done

            rm ${base}.zip
            rm ${base}.tar.gz
            cd ./ttmp
            7z a ../${base}.zip .
            tar -czvf ../${base}.tar.gz .
            cd ../
          fi

      - name: File check
        run: |
          find "build/dist-$config" -print0 ! -iname '*.md' ! -iname '*.h' -type f | xargs -0 file

      - name: UploadBinary
        uses: softprops/action-gh-release@v1
        if: startsWith(github.ref, 'refs/tags/v')
        with:
          draft: ${{contains(github.ref, 'draft')}}
          prerelease: ${{contains(github.ref, 'draft')}}
          files: |
            ${{ steps.package.outputs.SLANG_BINARY_ARCHIVE_ZIP }}
            ${{ steps.package.outputs.SLANG_BINARY_ARCHIVE_TAR }}
            ${{ steps.package.outputs.SLANG_DEBUG_INFO_ARCHIVE_ZIP }}
            ${{ steps.package.outputs.SLANG_DEBUG_INFO_ARCHIVE_TAR }}
            ${{ steps.notarize.outputs.SLANG_NOTARIZED_DIST }}
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

      - name: Checkout stdlib reference
        if: matrix.os == 'windows' && matrix.platform == 'x86_64'
        uses: actions/checkout@v4
        with:
          repository: shader-slang/stdlib-reference
          path: docs/stdlib-reference/
          token: ${{ secrets.UPDATE_STDLIB_REFERENCE_PAT }}
      - name: Update stdlib reference
        if: matrix.os == 'windows' && matrix.platform == 'x86_64'
        shell: powershell
        run: |
          cd docs/
          ls
          & ".\build_reference.ps1"
        env:
          GITHUB_TOKEN: ${{ secrets.UPDATE_STDLIB_REFERENCE_PAT }}