|
| 1 | +name: CI/CD |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main] |
| 6 | + tags: |
| 7 | + - "v*.*.*" |
| 8 | + pull_request: |
| 9 | + branches: [main] |
| 10 | + |
| 11 | +permissions: read-all |
| 12 | + |
| 13 | +concurrency: |
| 14 | + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} |
| 15 | + cancel-in-progress: true |
| 16 | + |
| 17 | +jobs: |
| 18 | + lint: |
| 19 | + name: Lint |
| 20 | + runs-on: ubuntu-latest |
| 21 | + steps: |
| 22 | + - name: Checkout code |
| 23 | + uses: actions/checkout@v4 |
| 24 | + - name: Set up Go |
| 25 | + uses: actions/setup-go@v5 |
| 26 | + with: |
| 27 | + go-version-file: "go.mod" |
| 28 | + - name: Run golangci-lint |
| 29 | + uses: golangci/golangci-lint-action@v6 |
| 30 | + with: |
| 31 | + version: v1.64 |
| 32 | + args: --timeout=5m |
| 33 | + |
| 34 | + test: |
| 35 | + name: Test |
| 36 | + needs: lint |
| 37 | + runs-on: ubuntu-latest |
| 38 | + steps: |
| 39 | + - name: Checkout code |
| 40 | + uses: actions/checkout@v4 |
| 41 | + with: |
| 42 | + fetch-depth: 0 |
| 43 | + |
| 44 | + - name: Set up Go |
| 45 | + uses: actions/setup-go@v5 |
| 46 | + with: |
| 47 | + go-version-file: "go.mod" |
| 48 | + |
| 49 | + - name: Install ShellSpec |
| 50 | + run: | |
| 51 | + SHELLSPEC_VERSION=0.28.1 |
| 52 | + curl -fsSL https://git.io/shellspec | sh -s ${SHELLSPEC_VERSION} --yes |
| 53 | + shellspec --version |
| 54 | +
|
| 55 | + - name: Run Unit Tests |
| 56 | + run: make test-units |
| 57 | + |
| 58 | + - name: Run Feature Tests |
| 59 | + run: make test-features |
| 60 | + |
| 61 | + - name: Run Fuzz Tests |
| 62 | + run: make test-fuzz FUZZ_TIME=10s # Shorter duration for CI |
| 63 | + |
| 64 | + create_release: |
| 65 | + name: Create GitHub Release |
| 66 | + if: startsWith(github.ref, 'refs/tags/v') |
| 67 | + needs: test |
| 68 | + runs-on: ubuntu-latest |
| 69 | + permissions: |
| 70 | + contents: write |
| 71 | + outputs: |
| 72 | + upload_url: ${{ steps.create_release.outputs.upload_url }} |
| 73 | + steps: |
| 74 | + - name: Checkout code |
| 75 | + uses: actions/checkout@v4 |
| 76 | + |
| 77 | + - name: Create Release |
| 78 | + id: create_release |
| 79 | + uses: actions/create-release@v1 |
| 80 | + env: |
| 81 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 82 | + with: |
| 83 | + tag_name: ${{ github.ref_name }} |
| 84 | + release_name: Release ${{ github.ref_name }} |
| 85 | + body: | |
| 86 | + Automated release for ${{ github.ref_name }}. |
| 87 | + See commit history for changes. |
| 88 | + draft: false |
| 89 | + prerelease: false |
| 90 | + |
| 91 | + build_and_upload_release_assets: |
| 92 | + name: Build and Upload Release Assets |
| 93 | + if: startsWith(github.ref, 'refs/tags/v') |
| 94 | + needs: create_release |
| 95 | + runs-on: ubuntu-latest |
| 96 | + permissions: |
| 97 | + contents: write |
| 98 | + strategy: |
| 99 | + matrix: |
| 100 | + goos: [linux, darwin] |
| 101 | + goarch: [amd64, arm64, 386, arm] |
| 102 | + exclude: |
| 103 | + - goos: darmin |
| 104 | + goarch: 386 |
| 105 | + - goos: darmin |
| 106 | + goarch: arm |
| 107 | + steps: |
| 108 | + - name: Checkout code |
| 109 | + uses: actions/checkout@v4 |
| 110 | + with: |
| 111 | + fetch-depth: 0 |
| 112 | + |
| 113 | + - name: Set up Go |
| 114 | + uses: actions/setup-go@v5 |
| 115 | + with: |
| 116 | + go-version-file: "go.mod" |
| 117 | + |
| 118 | + - name: Build for ${{ matrix.goos }}/${{ matrix.goarch }} |
| 119 | + run: make build GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }} |
| 120 | + env: |
| 121 | + GOOS: ${{ matrix.goos }} |
| 122 | + GOARCH: ${{ matrix.goarch }} |
| 123 | + |
| 124 | + - name: Prepare Asset Names |
| 125 | + id: prep_asset |
| 126 | + shell: bash |
| 127 | + run: | |
| 128 | + ARTIFACT_BASENAME="cmdjail-${{ matrix.goos }}-${{ matrix.goarch }}" |
| 129 | + ASSET_FILENAME="${ARTIFACT_BASENAME}" |
| 130 | + # Move the generic build output to the expected asset name |
| 131 | + mv build/cmdjail-${{ matrix.goos }}-${{ matrix.goarch}} build/${ASSET_FILENAME} |
| 132 | + echo "asset_path=build/${ASSET_FILENAME}" >> "$GITHUB_OUTPUT" |
| 133 | + echo "asset_name=${ASSET_FILENAME}" >> "$GITHUB_OUTPUT" |
| 134 | +
|
| 135 | + - name: Upload Release Asset for ${{ matrix.goos }}/${{ matrix.goarch }} |
| 136 | + uses: actions/upload-release-asset@v1 |
| 137 | + with: |
| 138 | + upload_url: ${{ needs.create_release.outputs.upload_url }} |
| 139 | + asset_path: ${{ steps.prep_asset.outputs.asset_path }} |
| 140 | + asset_name: ${{ steps.prep_asset.outputs.asset_name }} |
| 141 | + asset_content_type: application/octet-stream |
0 commit comments