Update readme and other instructions #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: Build and Deploy Preview | |
| on: | |
| pull_request: | |
| types: [opened, synchronize] | |
| paths: | |
| - 'src/main/resources/templates/**' | |
| - 'src/main/resources/static/**' | |
| - 'src/main/resources/explanations/**' | |
| jobs: | |
| build-preview: | |
| runs-on: ubuntu-latest | |
| # Temporarily disabled to avoid duplicate comments with pr-preview.yml | |
| # Both workflows provide similar functionality, pr-preview.yml is more comprehensive | |
| if: false | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up JDK 23 | |
| uses: actions/setup-java@v4 | |
| with: | |
| java-version: "23" | |
| distribution: "oracle" | |
| cache: "maven" | |
| - name: Extract version from pom.xml | |
| id: extract-version | |
| run: | | |
| echo "Extracting version from pom.xml..." | |
| chmod +x ./mvnw | |
| VERSION=$(./mvnw help:evaluate -Dexpression=project.version -q -DforceStdout) | |
| DOCKER_VERSION=${VERSION%-SNAPSHOT} | |
| echo "version=$VERSION" >> $GITHUB_OUTPUT | |
| echo "docker_version=$DOCKER_VERSION" >> $GITHUB_OUTPUT | |
| echo "Detected version: $VERSION" | |
| echo "Docker version: $DOCKER_VERSION" | |
| - name: Build application | |
| run: | | |
| echo "Building WrongSecrets application..." | |
| ./mvnw --no-transfer-progress clean package -DskipTests | |
| echo "Build completed. Checking target directory..." | |
| ls -la target/ | |
| echo "JAR file details:" | |
| ls -la target/*.jar || echo "No JAR files found in target/" | |
| - name: Build Docker image | |
| run: | | |
| echo "Building Docker image with version ${{ steps.extract-version.outputs.docker_version }}..." | |
| docker build --build-arg argBasedVersion="${{ steps.extract-version.outputs.docker_version }}" -t wrongsecrets-preview . | |
| echo "Docker image built successfully" | |
| docker save wrongsecrets-preview > wrongsecrets-preview.tar | |
| - name: Upload preview artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: wrongsecrets-preview-${{ github.event.number }} | |
| path: wrongsecrets-preview.tar | |
| - name: Comment on PR with instructions | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const prNumber = context.issue.number; | |
| const runId = context.runId; | |
| const comment = `🔨 **Preview Build Complete!** | |
| Your changes have been built successfully. | |
| **📦 Download & Test Locally:** | |
| 1. [📁 Download Docker Image Artifact](https://github.com/${{ github.repository }}/actions/runs/${runId}) (look for \`wrongsecrets-preview-${prNumber}\`) | |
| 2. Load and run the image: | |
| \`\`\`bash | |
| # Download the artifact, extract it, then: | |
| docker load < wrongsecrets-preview.tar | |
| docker run -p 8080:8080 wrongsecrets-preview | |
| \`\`\` | |
| Then visit: http://localhost:8080 | |
| **📝 Changed Files in this PR:**`; | |
| // Get the list of changed files | |
| const { data: files } = await github.rest.pulls.listFiles({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| pull_number: prNumber | |
| }); | |
| const templateFiles = files.filter(file => | |
| file.filename.includes('templates/') || | |
| file.filename.includes('static/') || | |
| file.filename.includes('explanations/') | |
| ); | |
| let filesList = ''; | |
| if (templateFiles.length > 0) { | |
| filesList = templateFiles.map(file => `- \`${file.filename}\``).join('\\n '); | |
| } else { | |
| filesList = '- No template/static files changed'; | |
| } | |
| const fullComment = comment + '\\n ' + filesList + ` | |
| --- | |
| <sub>Build completed by GitHub Actions</sub>`; | |
| github.rest.issues.createComment({ | |
| issue_number: prNumber, | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| body: fullComment | |
| }); |