feat: add project pinning and plan/grep tool handling #34
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: CI | |
| permissions: | |
| contents: write | |
| on: | |
| push: | |
| branches: ["**"] | |
| tags: ["v*"] | |
| pull_request: | |
| workflow_dispatch: | |
| inputs: | |
| version: | |
| description: "Release version (e.g., 1.2.3)" | |
| required: true | |
| type: string | |
| release_notes: | |
| description: "Release notes / changelog" | |
| required: true | |
| type: string | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Compute version | |
| id: version | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| BASE_VERSION="1.0" | |
| if [[ "${GITHUB_EVENT_NAME}" == "workflow_dispatch" ]]; then | |
| VERSION="${{ inputs.version }}" | |
| elif [[ "${GITHUB_REF}" == refs/tags/v* ]]; then | |
| VERSION="${GITHUB_REF_NAME#v}" | |
| else | |
| VERSION="${BASE_VERSION}.${GITHUB_RUN_NUMBER}" | |
| fi | |
| VERSION="${VERSION#v}" | |
| echo "version=${VERSION}" >> "${GITHUB_OUTPUT}" | |
| echo "Version: ${VERSION}" | |
| - name: Setup .NET | |
| uses: actions/setup-dotnet@v4 | |
| with: | |
| dotnet-version: "10.0.x" | |
| - name: Setup Node | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: "20" | |
| cache: "npm" | |
| cache-dependency-path: web/package-lock.json | |
| - name: Install frontend dependencies | |
| working-directory: web | |
| run: npm ci | |
| - name: Build frontend | |
| working-directory: web | |
| run: npm run build | |
| - name: Sync frontend into backend wwwroot | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| mkdir -p src/OneCode/wwwroot | |
| rsync -a --delete web/dist/ src/OneCode/wwwroot/ | |
| - name: Build backend | |
| if: github.event_name != 'workflow_dispatch' | |
| run: dotnet build src/OneCode/OneCode.csproj -c Release -p:Version=${{ steps.version.outputs.version }} -p:InformationalVersion=${{ steps.version.outputs.version }} | |
| - name: Publish backend | |
| if: github.event_name == 'workflow_dispatch' | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| for RID in linux-x64 osx-x64; do | |
| dotnet publish src/OneCode/OneCode.csproj -c Release -r "${RID}" --self-contained false -o "artifacts/publish/${RID}" -p:Version=${{ steps.version.outputs.version }} -p:InformationalVersion=${{ steps.version.outputs.version }} | |
| done | |
| WIN_PUBLISH_ROOT="artifacts/publish/win-x64" | |
| rm -rf "${WIN_PUBLISH_ROOT}" | |
| mkdir -p "${WIN_PUBLISH_ROOT}" | |
| dotnet publish src/OneCode.Win/OneCode.Win.csproj -c Release -r win-x64 --self-contained true -p:PublishSingleFile=true -p:Version=${{ steps.version.outputs.version }} -p:InformationalVersion=${{ steps.version.outputs.version }} -p:DebugType=None -p:DebugSymbols=false -o "${WIN_PUBLISH_ROOT}" | |
| if [[ ! -f "${WIN_PUBLISH_ROOT}/OneCode.Win.exe" ]]; then | |
| echo "OneCode.Win.exe not found in win-x64 publish output." | |
| exit 1 | |
| fi | |
| - name: Add platform scripts | |
| if: github.event_name == 'workflow_dispatch' | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| cat > "artifacts/publish/linux-x64/run.sh" <<'EOF' | |
| #!/usr/bin/env bash | |
| set -euo pipefail | |
| cd "$(dirname "$0")" | |
| export DOTNET_ENVIRONMENT=Production | |
| export ASPNETCORE_URLS="http://0.0.0.0:9110" | |
| echo "OneCode is running at $ASPNETCORE_URLS" | |
| echo "Open: http://localhost:9110" | |
| if [[ -f "./OneCode" ]]; then | |
| chmod +x "./OneCode" | |
| ./OneCode | |
| else | |
| dotnet "./OneCode.dll" | |
| fi | |
| EOF | |
| chmod +x "artifacts/publish/linux-x64/run.sh" | |
| cat > "artifacts/publish/linux-x64/install-service.sh" <<'EOF' | |
| #!/usr/bin/env bash | |
| set -euo pipefail | |
| SERVICE_NAME="${SERVICE_NAME:-onecode}" | |
| URLS="${URLS:-http://0.0.0.0:9110}" | |
| INSTALL_DIR="$(cd "$(dirname "$0")" && pwd)" | |
| if [[ $EUID -ne 0 ]]; then | |
| echo "Run this script with sudo." >&2 | |
| exit 1 | |
| fi | |
| if [[ -x "$INSTALL_DIR/OneCode" ]]; then | |
| EXECUTABLE="$INSTALL_DIR/OneCode" | |
| elif [[ -f "$INSTALL_DIR/OneCode.dll" ]]; then | |
| DOTNET_PATH="$(command -v dotnet || true)" | |
| if [[ -z "$DOTNET_PATH" ]]; then | |
| echo "dotnet not found in PATH." >&2 | |
| exit 1 | |
| fi | |
| EXECUTABLE="$DOTNET_PATH $INSTALL_DIR/OneCode.dll" | |
| else | |
| echo "OneCode executable not found in $INSTALL_DIR" >&2 | |
| exit 1 | |
| fi | |
| SERVICE_PATH="/etc/systemd/system/${SERVICE_NAME}.service" | |
| cat > "$SERVICE_PATH" <<SERVICE_EOF | |
| [Unit] | |
| Description=OneCode service | |
| After=network.target | |
| [Service] | |
| WorkingDirectory=$INSTALL_DIR | |
| ExecStart=$EXECUTABLE --urls $URLS | |
| Restart=always | |
| RestartSec=5 | |
| Environment=DOTNET_ENVIRONMENT=Production | |
| Environment=ASPNETCORE_URLS=$URLS | |
| [Install] | |
| WantedBy=multi-user.target | |
| SERVICE_EOF | |
| systemctl daemon-reload | |
| systemctl enable --now "$SERVICE_NAME" | |
| systemctl status "$SERVICE_NAME" --no-pager | |
| echo "URL: $URLS" | |
| echo "Open: http://localhost:9110" | |
| EOF | |
| chmod +x "artifacts/publish/linux-x64/install-service.sh" | |
| cat > "artifacts/publish/osx-x64/run.sh" <<'EOF' | |
| #!/usr/bin/env bash | |
| set -euo pipefail | |
| cd "$(dirname "$0")" | |
| export DOTNET_ENVIRONMENT=Production | |
| export ASPNETCORE_URLS="http://0.0.0.0:9110" | |
| echo "OneCode is running at $ASPNETCORE_URLS" | |
| echo "Open: http://localhost:9110" | |
| if [[ -f "./OneCode" ]]; then | |
| chmod +x "./OneCode" | |
| ./OneCode | |
| else | |
| dotnet "./OneCode.dll" | |
| fi | |
| EOF | |
| chmod +x "artifacts/publish/osx-x64/run.sh" | |
| cat > "artifacts/publish/osx-x64/install-service.sh" <<'EOF' | |
| #!/usr/bin/env bash | |
| set -euo pipefail | |
| SERVICE_NAME="${SERVICE_NAME:-com.onecode.service}" | |
| URLS="${URLS:-http://0.0.0.0:9110}" | |
| INSTALL_DIR="$(cd "$(dirname "$0")" && pwd)" | |
| if [[ $EUID -ne 0 ]]; then | |
| echo "Run this script with sudo." >&2 | |
| exit 1 | |
| fi | |
| if [[ -x "$INSTALL_DIR/OneCode" ]]; then | |
| program_args=("$INSTALL_DIR/OneCode" "--urls" "$URLS") | |
| else | |
| dll="$INSTALL_DIR/OneCode.dll" | |
| if [[ ! -f "$dll" ]]; then | |
| echo "OneCode executable not found in $INSTALL_DIR" >&2 | |
| exit 1 | |
| fi | |
| dotnet_path="$(command -v dotnet || true)" | |
| if [[ -z "$dotnet_path" ]]; then | |
| for candidate in /usr/local/share/dotnet/dotnet /opt/homebrew/bin/dotnet; do | |
| if [[ -x "$candidate" ]]; then | |
| dotnet_path="$candidate" | |
| break | |
| fi | |
| done | |
| fi | |
| if [[ -z "$dotnet_path" ]]; then | |
| echo "dotnet not found in PATH." >&2 | |
| exit 1 | |
| fi | |
| program_args=("$dotnet_path" "$dll" "--urls" "$URLS") | |
| fi | |
| plist_path="/Library/LaunchDaemons/${SERVICE_NAME}.plist" | |
| { | |
| echo '<?xml version="1.0" encoding="UTF-8"?>' | |
| echo '<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">' | |
| echo '<plist version="1.0">' | |
| echo '<dict>' | |
| echo ' <key>Label</key>' | |
| echo " <string>${SERVICE_NAME}</string>" | |
| echo ' <key>ProgramArguments</key>' | |
| echo ' <array>' | |
| for arg in "${program_args[@]}"; do | |
| printf ' <string>%s</string>\n' "$arg" | |
| done | |
| echo ' </array>' | |
| echo ' <key>WorkingDirectory</key>' | |
| echo " <string>${INSTALL_DIR}</string>" | |
| echo ' <key>EnvironmentVariables</key>' | |
| echo ' <dict>' | |
| echo ' <key>DOTNET_ENVIRONMENT</key>' | |
| echo ' <string>Production</string>' | |
| echo ' <key>ASPNETCORE_URLS</key>' | |
| echo " <string>${URLS}</string>" | |
| echo ' </dict>' | |
| echo ' <key>RunAtLoad</key>' | |
| echo ' <true/>' | |
| echo ' <key>KeepAlive</key>' | |
| echo ' <true/>' | |
| echo ' <key>StandardOutPath</key>' | |
| echo " <string>${INSTALL_DIR}/onecode.out.log</string>" | |
| echo ' <key>StandardErrorPath</key>' | |
| echo " <string>${INSTALL_DIR}/onecode.err.log</string>" | |
| echo '</dict>' | |
| echo '</plist>' | |
| } > "$plist_path" | |
| launchctl bootout system "$plist_path" >/dev/null 2>&1 || true | |
| launchctl bootstrap system "$plist_path" | |
| launchctl enable system/"${SERVICE_NAME}" | |
| launchctl kickstart -k system/"${SERVICE_NAME}" | |
| echo "URL: $URLS" | |
| echo "Open: http://localhost:9110" | |
| EOF | |
| chmod +x "artifacts/publish/osx-x64/install-service.sh" | |
| - name: Package release assets | |
| if: github.event_name == 'workflow_dispatch' | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| mkdir -p artifacts | |
| tar -czf "artifacts/OneCode-${{ steps.version.outputs.version }}-linux-x64.tar.gz" -C artifacts/publish/linux-x64 . | |
| tar -czf "artifacts/OneCode-${{ steps.version.outputs.version }}-osx-x64.tar.gz" -C artifacts/publish/osx-x64 . | |
| (cd artifacts/publish/win-x64 && zip -r "../../OneCode-${{ steps.version.outputs.version }}-win-x64.zip" .) | |
| - name: Create release | |
| if: github.event_name == 'workflow_dispatch' | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| RELEASE_NOTES: ${{ inputs.release_notes }} | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| TAG="v${{ steps.version.outputs.version }}" | |
| ASSETS=( | |
| "artifacts/OneCode-${{ steps.version.outputs.version }}-linux-x64.tar.gz" | |
| "artifacts/OneCode-${{ steps.version.outputs.version }}-osx-x64.tar.gz" | |
| "artifacts/OneCode-${{ steps.version.outputs.version }}-win-x64.zip" | |
| ) | |
| gh release create "${TAG}" "${ASSETS[@]}" --title "${TAG}" --notes "${RELEASE_NOTES}" --target "${GITHUB_SHA}" |