feat: add setup wizard for initial system configuration (#60) #7
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Release API | |
| on: | |
| push: | |
| tags: | |
| - 'api/v[0-9]+.[0-9]+.[0-9]+*' | |
| env: | |
| REGISTRY: ghcr.io | |
| IMAGE_NAME: ${{ github.repository_owner }}/tron-api | |
| jobs: | |
| # Run tests before release | |
| test: | |
| name: Run Tests | |
| uses: ./.github/workflows/tests.yml | |
| with: | |
| component: api | |
| secrets: inherit | |
| # Build and release only if tests pass | |
| build-and-release: | |
| runs-on: ubuntu-latest | |
| needs: test | |
| permissions: | |
| contents: write | |
| packages: write | |
| security-events: write | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Extract version from tag | |
| id: version | |
| run: | | |
| # Extract version from tag (api/v1.0.0 -> 1.0.0) | |
| TAG=${GITHUB_REF#refs/tags/api/v} | |
| echo "version=$TAG" >> $GITHUB_OUTPUT | |
| echo "Version: $TAG" | |
| # Extract major.minor for additional tags | |
| MAJOR=$(echo $TAG | cut -d. -f1) | |
| MINOR=$(echo $TAG | cut -d. -f2) | |
| echo "major=$MAJOR" >> $GITHUB_OUTPUT | |
| echo "minor=$MAJOR.$MINOR" >> $GITHUB_OUTPUT | |
| # Check if it's a prerelease (contains - like 1.0.0-beta.1) | |
| if [[ "$TAG" == *"-"* ]]; then | |
| echo "prerelease=true" >> $GITHUB_OUTPUT | |
| else | |
| echo "prerelease=false" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Log in to Container Registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ${{ env.REGISTRY }} | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Extract Docker metadata | |
| id: meta | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | |
| tags: | | |
| type=raw,value=${{ steps.version.outputs.version }} | |
| type=raw,value=${{ steps.version.outputs.minor }},enable=${{ steps.version.outputs.prerelease == 'false' }} | |
| type=raw,value=latest,enable=${{ steps.version.outputs.prerelease == 'false' }} | |
| - name: Build and push Docker image | |
| id: build | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: ./api | |
| file: ./api/Dockerfile.prod | |
| push: true | |
| tags: ${{ steps.meta.outputs.tags }} | |
| labels: ${{ steps.meta.outputs.labels }} | |
| cache-from: type=gha,scope=api | |
| cache-to: type=gha,mode=max,scope=api | |
| platforms: linux/amd64,linux/arm64 | |
| provenance: true | |
| sbom: true | |
| build-args: | | |
| APP_VERSION=${{ steps.version.outputs.version }} | |
| - name: Run Trivy vulnerability scanner | |
| uses: aquasecurity/trivy-action@master | |
| with: | |
| image-ref: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.version.outputs.version }} | |
| format: 'sarif' | |
| output: 'trivy-results.sarif' | |
| severity: 'CRITICAL,HIGH' | |
| - name: Upload Trivy scan results | |
| uses: github/codeql-action/upload-sarif@v3 | |
| if: always() | |
| with: | |
| sarif_file: 'trivy-results.sarif' | |
| - name: Generate changelog | |
| id: changelog | |
| run: | | |
| # Get the previous API tag | |
| PREV_TAG=$(git tag -l 'api/v*' --sort=-v:refname | head -2 | tail -1) | |
| if [ -z "$PREV_TAG" ] || [ "$PREV_TAG" == "api/v${{ steps.version.outputs.version }}" ]; then | |
| echo "changelog=Initial release" >> $GITHUB_OUTPUT | |
| else | |
| # Get commits between tags that affect the api directory | |
| CHANGELOG=$(git log --pretty=format:"- %s (%h)" $PREV_TAG..HEAD -- api/ | head -50) | |
| if [ -z "$CHANGELOG" ]; then | |
| CHANGELOG="No significant changes in API" | |
| fi | |
| # Use delimiter for multiline output | |
| echo "changelog<<EOF" >> $GITHUB_OUTPUT | |
| echo "$CHANGELOG" >> $GITHUB_OUTPUT | |
| echo "EOF" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Create GitHub Release | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| name: API v${{ steps.version.outputs.version }} | |
| tag_name: api/v${{ steps.version.outputs.version }} | |
| body: | | |
| ## API v${{ steps.version.outputs.version }} | |
| ### Docker Image | |
| ```bash | |
| docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.version.outputs.version }} | |
| ``` | |
| ### Image Digest | |
| `${{ steps.build.outputs.digest }}` | |
| ### Changes | |
| ${{ steps.changelog.outputs.changelog }} | |
| ### Installation | |
| ```bash | |
| helm repo add grid-labs-tech https://grid-labs-tech.github.io/charts | |
| helm repo update | |
| helm upgrade --install tron grid-labs-tech/tron \ | |
| --set api.image.tag=${{ steps.version.outputs.version }} | |
| ``` | |
| ### Verification | |
| All tests passed before this release was published. | |
| draft: false | |
| prerelease: ${{ steps.version.outputs.prerelease == 'true' }} |