From c42329093ec51ec5a779ab401e89a6dbd767fb4b Mon Sep 17 00:00:00 2001 From: Myzel394 <50424412+Myzel394@users.noreply.github.com> Date: Sun, 20 Oct 2024 13:36:25 +0200 Subject: [PATCH] fix(ci-cd): Fix ci:cd --- .github/workflows/release.yaml | 81 +++++++++++++++++----------------- flake.nix | 30 +++++++++++++ 2 files changed, 71 insertions(+), 40 deletions(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 7ae3835..6da06ed 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -60,7 +60,7 @@ jobs: build-extension: name: Build extension for ${{ matrix.target }} - runs-on: ${{ matrix.os }} + runs-on: ubuntu-latest needs: # Wait for server to build so that we know the checks have passed - build-server @@ -68,26 +68,26 @@ jobs: fail-fast: false matrix: include: - - target: x86_64-apple-darwin - os: macos-latest - cross: false - - target: aarch64-apple-darwin - os: macos-latest - cross: false + - goos: linux + goarch: amd64 + vscode_target: linux-x64 + - goos: linux + goarch: arm64 + vscode_target: linux-arm64 - - target: x86_64-unknown-linux-gnu - os: ubuntu-latest - cross: false - - target: aarch64-unknown-linux-gnu - os: ubuntu-latest - cross: false + - goos: darwin + goarch: amd64 + vscode_target: darwin-x64 + - goos: darwin + goarch: arm64 + vscode_target: darwin-arm64 - # - target: x86_64-pc-windows-msvc - # os: windows-latest - # cross: false - # - target: aarch64-pc-windows-msvc - # os: windows-latest - # cross: false + - goos: windows + goarch: amd64 + vscode_target: win32-x64 + - goos: windows + goarch: arm64 + vscode_target: win32-arm64 steps: - name: Checkout @@ -95,38 +95,39 @@ jobs: with: fetch-depth: 0 - - uses: cachix/install-nix-action@v27 + - name: Set up Go + uses: actions/setup-go@v5 with: - github_access_token: ${{ secrets.GITHUB_TOKEN }} + go-version: stable - - name: Check Flake - run: nix flake check + - name: Create bare extension + run: nix build .#"vs-code-extension-bare" - name: Build extension - run: nix build .#"vs-code-extension" + run: cd server && GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }} go build -a -gcflags=all="-l -B" -ldflags="-s -w" -o config-lsp - - name: Rename extension - run: cp result/*.vsix $(basename result/*.vsix)-${{ matrix.target }}.vsix + - name: Prepare folder + run: cp -rL result dist && chmod -R 777 dist + + - name: Move binary to extension + run: mv server/config-lsp dist/out/ + + - name: Shrink binary + if: ${{ matrix.goos == 'linux' }} + run: nix develop .#"shrink" --command bash -c "upx dist/out/config-lsp" + + - name: Package extension + run: nix develop .#"vs-code-extension" --command bash -c "cd dist && vsce package --target ${{ matrix.vscode_target }}" + + - name: Move vsix to root + run: mv dist/*.vsix . - uses: softprops/action-gh-release@v2 with: files: '*.vsix' - - name: Target to vs code target - id: vscode_target - run: | - if [ "${{ matrix.target }}" = "x86_64-apple-darwin" ]; then - echo "target=darwin-x64" >> $GITHUB_OUTPUT - elif [ "${{ matrix.target }}" = "aarch64-apple-darwin" ]; then - echo "target=darwin-arm64" >> $GITHUB_OUTPUT - elif [ "${{ matrix.target }}" = "x86_64-unknown-linux-gnu" ]; then - echo "target=linux-x64" >> $GITHUB_OUTPUT - elif [ "${{ matrix.target }}" = "aarch64-unknown-linux-gnu" ]; then - echo "target=linux-arm64" >> $GITHUB_OUTPUT - fi - - name: Upload extension to VS Code Marketplace - run: nix develop .#"vs-code-extension" --command bash -c "vsce publish --target ${{ steps.vscode_target.outputs.target }} --packagePath *.vsix" + run: nix develop .#"vs-code-extension" --command bash -c "vsce publish --packagePath *.vsix" env: VSCE_PAT: ${{ secrets.VSCE_TOKEN }} diff --git a/flake.nix b/flake.nix index 0273264..3f164af 100644 --- a/flake.nix +++ b/flake.nix @@ -68,6 +68,36 @@ in { packages = { default = server; + "vs-code-extension-bare" = let + name = "config-lsp"; + node-modules = pkgs.mkYarnPackage { + src = ./vs-code-extension; + name = name; + packageJSON = ./vs-code-extension/package.json; + yarnLock = ./vs-code-extension/yarn.lock; + yarnNix = ./vs-code-extension/yarn.nix; + + buildPhase = '' + yarn --offline run compile:prod + ''; + installPhase = '' + mkdir -p extension + + # No idea why this is being created + rm deps/${name}/config-lsp + + cp -rL deps/${name}/. extension + + mkdir -p $out + cp -r extension/. $out + ''; + distPhase = "true"; + + buildInputs = [ + pkgs.vsce + ]; + }; + in node-modules; "vs-code-extension" = let name = "config-lsp"; node-modules = pkgs.mkYarnPackage {