updated workflow to run on tag push #4
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: DIO Pipeline | |
| on: | |
| push: | |
| branches: [main] | |
| tags: | |
| - 'v*' | |
| pull_request: | |
| branches: [main] | |
| permissions: | |
| contents: read | |
| pull-requests: write | |
| env: | |
| GO_VERSION: "1.22" | |
| jobs: | |
| # Build and test the DIO tool itself | |
| build: | |
| name: Build & Test | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Go | |
| uses: actions/setup-go@v5 | |
| with: | |
| go-version: ${{ env.GO_VERSION }} | |
| - name: Download dependencies | |
| run: go mod download | |
| - name: Build | |
| run: go build -o bin/dio ./cmd/dio | |
| - name: Run tests | |
| run: go test -v -race -coverprofile=coverage.out ./... | |
| - name: Upload binary | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: dio-binary | |
| path: bin/dio | |
| # Run DIO against a sample Dockerfile | |
| analyze: | |
| name: Analyze Dockerfile | |
| runs-on: ubuntu-latest | |
| needs: build | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Download DIO binary | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: dio-binary | |
| path: bin | |
| - name: Make binary executable | |
| run: chmod +x bin/dio | |
| - name: Run DIO analysis | |
| run: bin/dio analyze testdata/Dockerfile.sample || true | |
| - name: Run DIO optimize (suggest mode) | |
| run: bin/dio optimize testdata/Dockerfile.sample || true | |
| - name: Run full pipeline | |
| run: | | |
| bin/dio run testdata/Dockerfile.sample \ | |
| --skip-scan \ | |
| --skip-build \ | |
| --output reports \ | |
| --policy policies/default.yaml || true | |
| - name: Upload reports | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: dio-reports | |
| path: reports/ | |
| if: always() | |
| - name: Comment PR with report | |
| if: github.event_name == 'pull_request' | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const fs = require('fs'); | |
| const reportPath = 'reports/report.md'; | |
| if (fs.existsSync(reportPath)) { | |
| const report = fs.readFileSync(reportPath, 'utf8'); | |
| github.rest.issues.createComment({ | |
| issue_number: context.issue.number, | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| body: report | |
| }); | |
| } | |
| # Security scanning (optional, requires Docker) | |
| security-scan: | |
| name: Security Scan | |
| runs-on: ubuntu-latest | |
| needs: build | |
| if: github.event_name == 'push' && github.ref == 'refs/heads/main' | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Install Trivy | |
| uses: aquasecurity/trivy-action@master | |
| with: | |
| scan-type: "config" | |
| scan-ref: "." | |
| format: "table" | |
| exit-code: "0" | |
| # Release (on tags) | |
| release: | |
| name: Release | |
| runs-on: ubuntu-latest | |
| needs: [build, analyze] | |
| if: startsWith(github.ref, 'refs/tags/v') | |
| permissions: | |
| contents: write | |
| strategy: | |
| matrix: | |
| goos: [linux, darwin, windows] | |
| goarch: [amd64, arm64] | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Go | |
| uses: actions/setup-go@v5 | |
| with: | |
| go-version: ${{ env.GO_VERSION }} | |
| - name: Build release binary | |
| env: | |
| GOOS: ${{ matrix.goos }} | |
| GOARCH: ${{ matrix.goarch }} | |
| run: | | |
| EXT="" | |
| if [ "$GOOS" = "windows" ]; then EXT=".exe"; fi | |
| go build -ldflags="-s -w -X main.version=${{ github.ref_name }} -X main.commit=${{ github.sha }}" \ | |
| -o "dio-${{ matrix.goos }}-${{ matrix.goarch }}${EXT}" ./cmd/dio | |
| - name: Upload release asset | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| files: dio-* |