|
| 1 | +name: Build and Deploy Preview |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + types: [opened, synchronize] |
| 6 | + paths: |
| 7 | + - 'src/main/resources/templates/**' |
| 8 | + - 'src/main/resources/static/**' |
| 9 | + - 'src/main/resources/explanations/**' |
| 10 | + |
| 11 | +jobs: |
| 12 | + build-preview: |
| 13 | + runs-on: ubuntu-latest |
| 14 | + steps: |
| 15 | + - name: Checkout code |
| 16 | + uses: actions/checkout@v4 |
| 17 | + |
| 18 | + - name: Set up JDK 23 |
| 19 | + uses: actions/setup-java@v4 |
| 20 | + with: |
| 21 | + java-version: "23" |
| 22 | + distribution: "oracle" |
| 23 | + cache: "maven" |
| 24 | + |
| 25 | + - name: Build application |
| 26 | + run: ./mvnw --no-transfer-progress clean package -DskipTests |
| 27 | + |
| 28 | + - name: Build Docker image |
| 29 | + run: | |
| 30 | + docker build -t wrongsecrets-preview . |
| 31 | + docker save wrongsecrets-preview > wrongsecrets-preview.tar |
| 32 | +
|
| 33 | + - name: Upload preview artifact |
| 34 | + uses: actions/upload-artifact@v4 |
| 35 | + with: |
| 36 | + name: wrongsecrets-preview-${{ github.event.number }} |
| 37 | + path: wrongsecrets-preview.tar |
| 38 | + |
| 39 | + - name: Comment on PR with instructions |
| 40 | + uses: actions/github-script@v7 |
| 41 | + with: |
| 42 | + script: | |
| 43 | + const comment = `🔨 **Preview Build Complete!** |
| 44 | +
|
| 45 | + Your changes have been built successfully. To test locally: |
| 46 | +
|
| 47 | + \`\`\`bash |
| 48 | + # Download the artifact and load the Docker image |
| 49 | + docker load < wrongsecrets-preview.tar |
| 50 | + docker run -p 8080:8080 wrongsecrets-preview |
| 51 | + \`\`\` |
| 52 | +
|
| 53 | + Then visit: http://localhost:8080 |
| 54 | +
|
| 55 | + **Changed Files in this PR:** |
| 56 | + - Templates: ${{ github.event.pull_request.changed_files }} |
| 57 | +
|
| 58 | + --- |
| 59 | + <sub>Build completed by GitHub Actions</sub>`; |
| 60 | +
|
| 61 | + github.rest.issues.createComment({ |
| 62 | + issue_number: context.issue.number, |
| 63 | + owner: context.repo.owner, |
| 64 | + repo: context.repo.repo, |
| 65 | + body: comment |
| 66 | + }); |
0 commit comments