Repository navigation
ci: save nim cache inline instead of post-job #80
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: OSX | |
| on: | |
| workflow_dispatch: | |
| push: | |
| branches: [main] | |
| tags: ['[0-9]+.[0-9]+.[0-9]+'] | |
| jobs: | |
| build: | |
| runs-on: macos-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Restore Nim toolchain cache | |
| id: cache-nim | |
| uses: actions/cache@v4 | |
| with: | |
| path: /Users/runner/nim-toolchain | |
| key: ${{ runner.os }}-${{ runner.arch }}-nim-toolchain-${{ hashFiles('*.nimble') }} | |
| restore-keys: | | |
| ${{ runner.os }}-${{ runner.arch }}-nim-toolchain- | |
| - uses: jiro4989/setup-nim-action@v2 | |
| with: | |
| nim-version: stable | |
| repo-token: ${{ secrets.GITHUB_TOKEN }} | |
| parent-nim-install-directory: $HOME | |
| nim-install-directory: nim-toolchain | |
| - name: Save Nim toolchain cache | |
| if: steps.cache-nim.outputs.cache-hit != 'true' | |
| uses: actions/cache@v4 | |
| with: | |
| path: /Users/runner/nim-toolchain | |
| key: ${{ runner.os }}-${{ runner.arch }}-nim-toolchain-${{ hashFiles('*.nimble') }} | |
| - name: Install dependencies | |
| run: nimble install -y --depsOnly | |
| - name: Compute build flags | |
| shell: bash | |
| run: | | |
| if [[ "${GITHUB_REF}" == refs/tags/* ]]; then | |
| # autoupdate on releases only | |
| echo "BUILD_FLAGS=-d:autoUpdate" >> "$GITHUB_ENV" | |
| fi | |
| - name: Build | |
| run: nimble build -y -d:release ${{ env.BUILD_FLAGS }} | |
| - name: Build x86_64 and create universal binary | |
| env: | |
| SLICE_DIR: ${{ runner.temp }} | |
| run: | | |
| mv 3code "$SLICE_DIR/3code-arm64" | |
| rm -rf ~/.cache/nim/threecode_r | |
| nim c -d:release ${{ env.BUILD_FLAGS }} --passC:"-arch x86_64" --passL:"-arch x86_64" --cpu:amd64 -o:"$SLICE_DIR/3code-x86_64" src/threecode.nim | |
| lipo -create "$SLICE_DIR/3code-arm64" "$SLICE_DIR/3code-x86_64" -output 3code | |
| file 3code | |
| - name: Run tests | |
| run: nimble test | |
| timeout-minutes: 20 | |
| - name: Package | |
| run: | | |
| mkdir -p 3code-macos-universal | |
| cp 3code 3code-macos-universal/ | |
| # Capture the version from the built binary so it can be checked | |
| # without running the binary on its target OS. | |
| ./3code -v > 3code-macos-universal/VERSION | |
| cp README.md LICENSE 3code-macos-universal/ | |
| OPENSSL_PREFIX="$(brew --prefix openssl@3)" | |
| cp "${OPENSSL_PREFIX}/lib/libssl.3.dylib" 3code-macos-universal/ | |
| cp "${OPENSSL_PREFIX}/lib/libcrypto.3.dylib" 3code-macos-universal/ | |
| chmod +w 3code-macos-universal/libssl.3.dylib 3code-macos-universal/libcrypto.3.dylib | |
| install_name_tool -id @loader_path/libcrypto.3.dylib 3code-macos-universal/libcrypto.3.dylib | |
| install_name_tool -id @loader_path/libssl.3.dylib 3code-macos-universal/libssl.3.dylib | |
| install_name_tool -change "${OPENSSL_PREFIX}/lib/libcrypto.3.dylib" \ | |
| @loader_path/libcrypto.3.dylib 3code-macos-universal/libssl.3.dylib | |
| ln -sf libssl.3.dylib 3code-macos-universal/libssl.dylib | |
| ln -sf libcrypto.3.dylib 3code-macos-universal/libcrypto.dylib | |
| curl -fsSL https://curl.se/ca/cacert.pem -o 3code-macos-universal/cacert.pem | |
| tar czf 3code-macos-universal.tar.gz 3code-macos-universal | |
| - name: Upload artifact (GitHub Actions) | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: 3code-macos-universal | |
| path: 3code-macos-universal.tar.gz | |
| - name: Upload artifact to 3code.capocasa.dev | |
| if: github.ref == 'refs/heads/main' | |
| run: | | |
| curl -f -H "Authorization: Bearer ${{ secrets.RELEASE_SECRET }}" -F "file=@3code-macos-universal.tar.gz" \ | |
| https://3code.capocasa.dev/main/upload.nim |