|
1 | 1 | name: Release |
2 | 2 |
|
3 | | -# DISABLED: Uncomment the 'on' block below to enable releases |
4 | | -# on: |
5 | | -# push: |
6 | | -# tags: |
7 | | -# - 'v*' |
8 | | - |
9 | 3 | on: |
10 | | - workflow_dispatch: # Manual trigger only for now |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - 'v*' |
| 7 | + workflow_dispatch: |
| 8 | + inputs: |
| 9 | + version: |
| 10 | + description: 'Version to release (e.g., 0.2.0)' |
| 11 | + required: true |
| 12 | + type: string |
11 | 13 |
|
12 | 14 | env: |
13 | 15 | CARGO_TERM_COLOR: always |
14 | | - REGISTRY: ghcr.io |
15 | | - IMAGE_NAME: ${{ github.repository_owner }}/sentinel-js |
| 16 | + BINARY_NAME: sentinel-js-agent |
16 | 17 |
|
17 | 18 | jobs: |
18 | | - publish: |
19 | | - runs-on: ubuntu-latest |
20 | | - if: false # Disabled - set to true to enable crates.io publishing |
21 | | - steps: |
22 | | - - uses: actions/checkout@v4 |
23 | | - |
24 | | - - name: Install Rust |
25 | | - uses: dtolnay/rust-toolchain@stable |
26 | | - |
27 | | - - name: Publish to crates.io |
28 | | - run: cargo publish |
29 | | - env: |
30 | | - CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} |
31 | | - continue-on-error: true |
32 | | - |
33 | 19 | build: |
34 | | - runs-on: ubuntu-latest |
35 | | - if: false # Disabled - set to true to enable builds |
| 20 | + name: Build ${{ matrix.target }} |
| 21 | + runs-on: ${{ matrix.os }} |
| 22 | + strategy: |
| 23 | + fail-fast: false |
| 24 | + matrix: |
| 25 | + include: |
| 26 | + - target: x86_64-unknown-linux-gnu |
| 27 | + os: ubuntu-latest |
| 28 | + artifact: linux-x86_64 |
| 29 | + - target: aarch64-unknown-linux-gnu |
| 30 | + os: ubuntu-latest |
| 31 | + artifact: linux-aarch64 |
| 32 | + cross: true |
| 33 | + - target: aarch64-apple-darwin |
| 34 | + os: macos-latest |
| 35 | + artifact: darwin-aarch64 |
36 | 36 |
|
37 | 37 | steps: |
38 | 38 | - uses: actions/checkout@v4 |
39 | 39 |
|
40 | 40 | - name: Install Rust |
41 | 41 | uses: dtolnay/rust-toolchain@stable |
| 42 | + with: |
| 43 | + targets: ${{ matrix.target }} |
42 | 44 |
|
43 | | - - name: Install build dependencies |
| 45 | + - name: Install cross-compilation tools |
| 46 | + if: matrix.cross |
44 | 47 | run: | |
45 | 48 | sudo apt-get update |
46 | | - sudo apt-get install -y protobuf-compiler |
47 | | -
|
48 | | - - name: Build release binary |
49 | | - run: | |
50 | | - cargo build --release |
51 | | - strip target/release/sentinel-js-agent |
| 49 | + sudo apt-get install -y gcc-aarch64-linux-gnu |
| 50 | + echo "CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc" >> $GITHUB_ENV |
52 | 51 |
|
53 | | - - name: Prepare artifacts |
54 | | - run: | |
55 | | - mkdir -p artifacts |
56 | | - cp target/release/sentinel-js-agent artifacts/ |
57 | | -
|
58 | | - - name: Upload artifacts |
59 | | - uses: actions/upload-artifact@v4 |
| 52 | + - name: Cache cargo |
| 53 | + uses: actions/cache@v4 |
60 | 54 | with: |
61 | | - name: sentinel-js-linux-amd64 |
62 | | - path: artifacts/ |
63 | | - retention-days: 7 |
64 | | - |
65 | | - docker: |
66 | | - needs: build |
67 | | - runs-on: ubuntu-latest |
68 | | - if: false # Disabled - set to true to enable Docker builds |
69 | | - permissions: |
70 | | - contents: read |
71 | | - packages: write |
72 | | - |
73 | | - steps: |
74 | | - - uses: actions/checkout@v4 |
| 55 | + path: | |
| 56 | + ~/.cargo/bin/ |
| 57 | + ~/.cargo/registry/index/ |
| 58 | + ~/.cargo/registry/cache/ |
| 59 | + ~/.cargo/git/db/ |
| 60 | + target/ |
| 61 | + key: ${{ runner.os }}-${{ matrix.target }}-cargo-${{ hashFiles('**/Cargo.lock') }} |
| 62 | + restore-keys: | |
| 63 | + ${{ runner.os }}-${{ matrix.target }}-cargo- |
75 | 64 |
|
76 | | - - name: Download AMD64 artifact |
77 | | - uses: actions/download-artifact@v4 |
78 | | - with: |
79 | | - name: sentinel-js-linux-amd64 |
80 | | - path: artifacts/linux-amd64 |
| 65 | + - name: Build release binary |
| 66 | + run: cargo build --release --target ${{ matrix.target }} |
81 | 67 |
|
82 | | - - name: Prepare artifact |
83 | | - run: chmod +x artifacts/linux-amd64/sentinel-js-agent |
| 68 | + - name: Strip binary (Linux native) |
| 69 | + if: matrix.target == 'x86_64-unknown-linux-gnu' |
| 70 | + run: strip target/${{ matrix.target }}/release/${{ env.BINARY_NAME }} |
84 | 71 |
|
85 | | - - name: Set up Docker Buildx |
86 | | - uses: docker/setup-buildx-action@v3 |
| 72 | + - name: Strip binary (Linux cross) |
| 73 | + if: matrix.cross |
| 74 | + run: aarch64-linux-gnu-strip target/${{ matrix.target }}/release/${{ env.BINARY_NAME }} |
87 | 75 |
|
88 | | - - name: Log in to Container Registry |
89 | | - uses: docker/login-action@v3 |
90 | | - with: |
91 | | - registry: ${{ env.REGISTRY }} |
92 | | - username: ${{ github.actor }} |
93 | | - password: ${{ secrets.GITHUB_TOKEN }} |
| 76 | + - name: Strip binary (macOS) |
| 77 | + if: contains(matrix.target, 'darwin') |
| 78 | + run: strip target/${{ matrix.target }}/release/${{ env.BINARY_NAME }} |
94 | 79 |
|
95 | | - - name: Extract version |
| 80 | + - name: Determine version |
96 | 81 | id: version |
97 | | - run: echo "version=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT |
| 82 | + run: | |
| 83 | + if [ -n "${{ inputs.version }}" ]; then |
| 84 | + echo "version=${{ inputs.version }}" >> $GITHUB_OUTPUT |
| 85 | + else |
| 86 | + echo "version=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT |
| 87 | + fi |
98 | 88 |
|
99 | | - - name: Build and push image |
100 | | - uses: docker/build-push-action@v5 |
| 89 | + - name: Package binary |
| 90 | + run: | |
| 91 | + mkdir -p dist |
| 92 | + cp target/${{ matrix.target }}/release/${{ env.BINARY_NAME }} dist/ |
| 93 | + cd dist |
| 94 | + tar -czvf ${{ env.BINARY_NAME }}-${{ steps.version.outputs.version }}-${{ matrix.artifact }}.tar.gz ${{ env.BINARY_NAME }} |
| 95 | +
|
| 96 | + - name: Upload artifact |
| 97 | + uses: actions/upload-artifact@v4 |
101 | 98 | with: |
102 | | - context: artifacts/linux-amd64 |
103 | | - file: ./Dockerfile |
104 | | - target: prebuilt |
105 | | - platforms: linux/amd64 |
106 | | - push: true |
107 | | - tags: | |
108 | | - ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.version.outputs.version }} |
109 | | - ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest |
110 | | - provenance: false |
| 99 | + name: ${{ matrix.artifact }} |
| 100 | + path: dist/*.tar.gz |
| 101 | + retention-days: 1 |
111 | 102 |
|
112 | 103 | release: |
113 | | - needs: [build, docker] |
| 104 | + name: Create Release |
| 105 | + needs: build |
114 | 106 | runs-on: ubuntu-latest |
115 | | - if: false # Disabled - set to true to enable releases |
116 | 107 | permissions: |
117 | 108 | contents: write |
118 | 109 |
|
119 | 110 | steps: |
120 | 111 | - uses: actions/checkout@v4 |
121 | 112 |
|
122 | | - - name: Download AMD64 artifact |
| 113 | + - name: Determine version |
| 114 | + id: version |
| 115 | + run: | |
| 116 | + if [ -n "${{ inputs.version }}" ]; then |
| 117 | + echo "version=${{ inputs.version }}" >> $GITHUB_OUTPUT |
| 118 | + echo "tag=v${{ inputs.version }}" >> $GITHUB_OUTPUT |
| 119 | + else |
| 120 | + echo "version=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT |
| 121 | + echo "tag=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT |
| 122 | + fi |
| 123 | +
|
| 124 | + - name: Download all artifacts |
123 | 125 | uses: actions/download-artifact@v4 |
124 | 126 | with: |
125 | | - name: sentinel-js-linux-amd64 |
126 | | - path: artifacts/linux-amd64 |
| 127 | + path: artifacts |
| 128 | + |
| 129 | + - name: List artifacts |
| 130 | + run: find artifacts -type f |
127 | 131 |
|
128 | | - - name: Prepare release files |
| 132 | + - name: Collect release files |
129 | 133 | run: | |
130 | 134 | mkdir -p release |
131 | | - mv artifacts/linux-amd64/sentinel-js-agent release/sentinel-js-agent-linux-amd64 |
| 135 | + find artifacts -name '*.tar.gz' -exec mv {} release/ \; |
| 136 | + ls -la release/ |
| 137 | +
|
| 138 | + - name: Delete existing release if exists |
| 139 | + run: gh release delete "${{ steps.version.outputs.tag }}" --yes || true |
| 140 | + env: |
| 141 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
132 | 142 |
|
133 | 143 | - name: Create release |
134 | | - uses: softprops/action-gh-release@v1 |
| 144 | + uses: softprops/action-gh-release@v2 |
135 | 145 | with: |
| 146 | + tag_name: ${{ steps.version.outputs.tag }} |
| 147 | + name: v${{ steps.version.outputs.version }} |
136 | 148 | files: release/* |
| 149 | + fail_on_unmatched_files: true |
137 | 150 | generate_release_notes: true |
| 151 | + env: |
| 152 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments