|
| 1 | +name: Release |
| 2 | +on: |
| 3 | + push: |
| 4 | + branches: |
| 5 | + - main |
| 6 | + |
| 7 | +env: |
| 8 | + CARGO_TERM_COLOR: always |
| 9 | + REGISTRY: ghcr.io |
| 10 | + IMAGE_NAME: ${{ github.repository }} |
| 11 | + |
| 12 | +jobs: |
| 13 | + release: |
| 14 | + name: Release |
| 15 | + runs-on: ubuntu-24.04 |
| 16 | + permissions: |
| 17 | + contents: write |
| 18 | + packages: write |
| 19 | + |
| 20 | + steps: |
| 21 | + - name: Checkout |
| 22 | + uses: actions/checkout@v4 |
| 23 | + with: |
| 24 | + fetch-depth: 0 |
| 25 | + |
| 26 | + - name: Set image name to lowercase |
| 27 | + run: echo "IMAGE_NAME_LC=${IMAGE_NAME,,}" >> $GITHUB_ENV |
| 28 | + env: |
| 29 | + IMAGE_NAME: ${{ github.repository }} |
| 30 | + |
| 31 | + - name: Install Rust toolchain |
| 32 | + uses: dtolnay/rust-toolchain@stable |
| 33 | + with: |
| 34 | + components: clippy, rustfmt |
| 35 | + |
| 36 | + - name: Cache cargo |
| 37 | + uses: Swatinem/rust-cache@v2 |
| 38 | + |
| 39 | + - name: Run Clippy |
| 40 | + run: cargo clippy --no-deps -- -Dwarnings |
| 41 | + |
| 42 | + - name: Run rustfmt |
| 43 | + run: cargo fmt --check |
| 44 | + |
| 45 | + - name: Build |
| 46 | + run: cargo build --release |
| 47 | + |
| 48 | + - name: Run tests |
| 49 | + run: cargo test |
| 50 | + |
| 51 | + - name: Install GitVersion |
| 52 | + uses: gittools/actions/gitversion/setup@v3 |
| 53 | + |
| 54 | + - name: Create GitVersion.yml |
| 55 | + run: | |
| 56 | + cat <<EOF > GitVersion.yml |
| 57 | + major-version-bump-message: '(breaking|major|incompatible):' |
| 58 | + minor-version-bump-message: '(feature|minor|enhancement|new|update|improvement|upgrade|feat):' |
| 59 | + patch-version-bump-message: '(fix|patch|bugfix|hotfix|correction|adjustment|tweak):' |
| 60 | + no-bump-message: '(none|skip|no-release|trivial|docs|documentation|style|refactor|chore|chore\(deps\)|test):' |
| 61 | + EOF |
| 62 | +
|
| 63 | + - name: Run GitVersion |
| 64 | + id: gitversion |
| 65 | + uses: gittools/actions/gitversion/execute@v3 |
| 66 | + |
| 67 | + - name: Display GitVersion |
| 68 | + run: | |
| 69 | + echo "Version: ${{ env.majorMinorPatch }}" |
| 70 | +
|
| 71 | + - name: Set up Docker Buildx |
| 72 | + uses: docker/setup-buildx-action@v3 |
| 73 | + |
| 74 | + - name: Log in to Container Registry |
| 75 | + uses: docker/login-action@v3 |
| 76 | + with: |
| 77 | + registry: ${{ env.REGISTRY }} |
| 78 | + username: ${{ github.actor }} |
| 79 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 80 | + |
| 81 | + - name: Build and push Docker image |
| 82 | + uses: docker/build-push-action@v6 |
| 83 | + with: |
| 84 | + context: . |
| 85 | + platforms: linux/amd64,linux/arm64 |
| 86 | + push: true |
| 87 | + tags: | |
| 88 | + ${{ env.REGISTRY }}/${{ env.IMAGE_NAME_LC }}:${{ env.majorMinorPatch }} |
| 89 | + ${{ env.REGISTRY }}/${{ env.IMAGE_NAME_LC }}:latest |
| 90 | + cache-from: type=gha |
| 91 | + cache-to: type=gha,mode=max |
| 92 | + |
| 93 | + - name: Create tag |
| 94 | + uses: rickstaa/action-create-tag@v1 |
| 95 | + with: |
| 96 | + tag: v${{ env.majorMinorPatch }} |
| 97 | + force_push_tag: true |
| 98 | + |
| 99 | + - name: Create GitHub release |
| 100 | + uses: ncipollo/release-action@v1 |
| 101 | + with: |
| 102 | + generateReleaseNotes: true |
| 103 | + tag: v${{ env.majorMinorPatch }} |
| 104 | + |
| 105 | + # Integration tests |
| 106 | + - name: Pull image |
| 107 | + run: docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_NAME_LC }}:${{ env.majorMinorPatch }} |
| 108 | + |
| 109 | + - name: Run container |
| 110 | + run: | |
| 111 | + docker run -d --name naolametric-test \ |
| 112 | + -p 8080:8080 \ |
| 113 | + ${{ env.REGISTRY }}/${{ env.IMAGE_NAME_LC }}:${{ env.majorMinorPatch }} |
| 114 | + sleep 3 |
| 115 | +
|
| 116 | + - name: Test health endpoint |
| 117 | + run: | |
| 118 | + response=$(curl -s http://localhost:8080/health) |
| 119 | + if [ "$response" != "OK" ]; then |
| 120 | + echo "Health check failed: $response" |
| 121 | + exit 1 |
| 122 | + fi |
| 123 | + echo "Health check passed" |
| 124 | +
|
| 125 | + - name: Test stops endpoint |
| 126 | + run: | |
| 127 | + response=$(curl -s "http://localhost:8080/stops?search=commerce&limit=1") |
| 128 | + if ! echo "$response" | grep -q "COMM"; then |
| 129 | + echo "Stops endpoint failed: $response" |
| 130 | + exit 1 |
| 131 | + fi |
| 132 | + echo "Stops endpoint passed" |
| 133 | +
|
| 134 | + - name: Test main endpoint |
| 135 | + run: | |
| 136 | + response=$(curl -s "http://localhost:8080/?stop=COMM") |
| 137 | + if ! echo "$response" | grep -q "frames"; then |
| 138 | + echo "Main endpoint failed: $response" |
| 139 | + exit 1 |
| 140 | + fi |
| 141 | + echo "Main endpoint passed" |
| 142 | +
|
| 143 | + - name: Show logs |
| 144 | + if: always() |
| 145 | + run: docker logs naolametric-test || true |
| 146 | + |
| 147 | + - name: Cleanup |
| 148 | + if: always() |
| 149 | + run: docker rm -f naolametric-test || true |
0 commit comments