|
| 1 | +name: Release new version |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - master |
| 7 | + paths: |
| 8 | + - Cargo.toml |
| 9 | +jobs: |
| 10 | + get-newer-version: |
| 11 | + runs-on: ubuntu-latest |
| 12 | + outputs: |
| 13 | + new-version: ${{ steps.check.outputs.new_version }} |
| 14 | + steps: |
| 15 | + - name: Checkout repository |
| 16 | + uses: actions/checkout@v4 |
| 17 | + with: |
| 18 | + fetch-tags: true |
| 19 | + |
| 20 | + - name: Extract version from Cargo.toml |
| 21 | + id: extract |
| 22 | + run: | |
| 23 | + VERSION=$(grep -m1 '^version\s*=' Cargo.toml | sed -E 's/version\s*=\s*"([^"]+)".*/\1/') |
| 24 | + echo "Extracted version: $VERSION" |
| 25 | + echo "version=$VERSION" >> $GITHUB_OUTPUT |
| 26 | +
|
| 27 | + - name: Get latest tag |
| 28 | + id: latest |
| 29 | + run: | |
| 30 | + LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "none") |
| 31 | + echo "Latest tag: $LATEST_TAG" |
| 32 | + echo "latest_tag=$LATEST_TAG" >> $GITHUB_OUTPUT |
| 33 | +
|
| 34 | + - name: Check if version is new |
| 35 | + id: check |
| 36 | + run: | |
| 37 | + VERSION="${{ steps.extract.outputs.version }}" |
| 38 | + LATEST="${{ steps.latest.outputs.latest_tag }}" |
| 39 | + if [ "$VERSION" = "$LATEST" ]; then |
| 40 | + echo "No new version detected." |
| 41 | + echo "new_version=" >> $GITHUB_OUTPUT |
| 42 | + else |
| 43 | + echo "New version detected: $VERSION" |
| 44 | + echo "new_version=$VERSION" >> $GITHUB_OUTPUT |
| 45 | + fi |
| 46 | +
|
| 47 | + build: |
| 48 | + name: Build ${{ matrix.os }}-${{ matrix.arch }} |
| 49 | + needs: get-newer-version |
| 50 | + if: needs.get-newer-version.outputs.new-version != '' |
| 51 | + runs-on: ${{ matrix.runner }} |
| 52 | + strategy: |
| 53 | + matrix: |
| 54 | + include: |
| 55 | + - runner: ubuntu-latest |
| 56 | + os: linux |
| 57 | + arch: arm64 |
| 58 | + - runner: ubuntu-latest |
| 59 | + os: linux |
| 60 | + arch: amd64 |
| 61 | + - runner: macos-latest |
| 62 | + os: darwin |
| 63 | + arch: arm64 |
| 64 | + - runner: macos-latest |
| 65 | + os: darwin |
| 66 | + arch: amd64 |
| 67 | + # - runner: ubuntu-latest # Not supported by the CLI Scanner yet |
| 68 | + # os: windows |
| 69 | + # arch: amd64 |
| 70 | + steps: |
| 71 | + - name: Checkout code |
| 72 | + uses: actions/checkout@v4 |
| 73 | + |
| 74 | + - name: Install Nix |
| 75 | + uses: DeterminateSystems/nix-installer-action@main |
| 76 | + |
| 77 | + - name: Configure Nix cache |
| 78 | + uses: DeterminateSystems/flakehub-cache-action@main |
| 79 | + |
| 80 | + - name: Build LSP for ${{ matrix.os }}-${{ matrix.arch }} |
| 81 | + run: nix build -L .#sysdig-lsp-${{ matrix.os }}-${{ matrix.arch }} |
| 82 | + |
| 83 | + - name: Copy binary built |
| 84 | + run: cp -a ./result/bin/sysdig-lsp /tmp/sysdig-lsp-${{ matrix.os }}-${{ matrix.arch }} |
| 85 | + |
| 86 | + - name: Upload binary |
| 87 | + uses: actions/upload-artifact@v4 |
| 88 | + with: |
| 89 | + name: sysdig-lsp-${{ matrix.os }}-${{ matrix.arch }} |
| 90 | + path: /tmp/sysdig-lsp-${{ matrix.os }}-${{ matrix.arch }} |
| 91 | + if-no-files-found: error |
| 92 | + retention-days: 1 |
| 93 | + |
| 94 | + release: |
| 95 | + name: Create release at Github |
| 96 | + needs: [ build, get-newer-version ] |
| 97 | + if: needs.get-newer-version.outputs.new-version != '' |
| 98 | + runs-on: ubuntu-latest |
| 99 | + permissions: |
| 100 | + contents: write # Required for release creation |
| 101 | + steps: |
| 102 | + - uses: actions/checkout@v4 |
| 103 | + with: |
| 104 | + fetch-depth: 0 |
| 105 | + fetch-tags: true |
| 106 | + |
| 107 | + - name: Install Nix |
| 108 | + uses: DeterminateSystems/nix-installer-action@main |
| 109 | + |
| 110 | + - name: Configure Nix cache |
| 111 | + uses: DeterminateSystems/flakehub-cache-action@main |
| 112 | + |
| 113 | + - name: Install git-chglog |
| 114 | + run: nix profile install nixpkgs#git-chglog |
| 115 | + |
| 116 | + - name: Tag with version ${{ needs.get-newer-version.outputs.new-version }} |
| 117 | + run: git tag ${{ needs.get-newer-version.outputs.new-version }} |
| 118 | + |
| 119 | + - name: Generate changelog |
| 120 | + run: git-chglog -c .github/git-chglog/config.yml -o RELEASE_CHANGELOG.md $(git describe --tags $(git rev-list --tags --max-count=1)) |
| 121 | + |
| 122 | + - name: Download artifacts |
| 123 | + uses: actions/download-artifact@v4 |
| 124 | + with: |
| 125 | + pattern: sysdig-lsp-* |
| 126 | + path: /tmp/ |
| 127 | + merge-multiple: true |
| 128 | + |
| 129 | + - name: Create release |
| 130 | + uses: softprops/action-gh-release@v2 |
| 131 | + with: |
| 132 | + name: Sysdig LSP ${{ needs.get-newer-version.outputs.new-version }} |
| 133 | + tag_name: ${{ needs.get-newer-version.outputs.new-version }} |
| 134 | + prerelease: false |
| 135 | + body_path: RELEASE_CHANGELOG.md |
| 136 | + files: | |
| 137 | + /tmp/sysdig-lsp-* |
0 commit comments