Deploy to Test Server #19
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: Deploy to Test Server | |
| on: | |
| workflow_run: | |
| workflows: | |
| - 'Build WAR' | |
| types: | |
| - completed | |
| jobs: | |
| deploy-test: | |
| runs-on: ubuntu-latest | |
| if: ${{ github.event.workflow_run.conclusion == 'success' }} | |
| steps: | |
| - name: Checkout source | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: main | |
| - name: Download built WAR | |
| uses: actions/github-script@v7 | |
| id: download | |
| with: | |
| script: | | |
| const run_id = context.payload.workflow_run.id; | |
| // List artifacts for this specific run | |
| const artifacts = await github.rest.actions.listWorkflowRunArtifacts({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| run_id: run_id, | |
| }); | |
| const artifact = artifacts.data.artifacts.find(a => a.name === "war-file"); | |
| if (!artifact) throw new Error("WAR artifact not found"); | |
| const download = await github.rest.actions.downloadArtifact({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| artifact_id: artifact.id, | |
| archive_format: "zip", | |
| }); | |
| const fs = require("fs"); | |
| fs.writeFileSync("artifact.zip", Buffer.from(download.data)); | |
| - name: Unzip artifact | |
| run: unzip artifact.zip | |
| - name: Rsync WAR to Test Server | |
| uses: burnett01/[email protected] | |
| with: | |
| remote_host: ${{ secrets.TEST_SERVER_HOST }} | |
| remote_user: ${{ secrets.TEST_SERVER_USERNAME }} | |
| remote_key: ${{ secrets.TEST_SERVER_KEY }} | |
| path: HealthNutrition.war | |
| remote_path: /tmp/ | |
| - name: Install WAR on Test Server | |
| uses: appleboy/ssh-action@v1 | |
| with: | |
| host: ${{ secrets.TEST_SERVER_HOST }} | |
| username: ${{ secrets.TEST_SERVER_USERNAME }} | |
| key: ${{ secrets.TEST_SERVER_KEY }} | |
| script: /root/tomcat/HealthNutrition/deploy.sh |