-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #94 from NJUPT-SAST/feat/github
Feat/GitHub
- Loading branch information
Showing
13 changed files
with
318 additions
and
163 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,76 +10,76 @@ on: | |
|
||
jobs: | ||
build: | ||
if: github.event.pull_request.merged | ||
if: github.event.pull_request.merged | ||
runs-on: ubuntu-22.04 | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v2 | ||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v3 | ||
|
||
- name: Cache Docker layers | ||
uses: actions/cache@v3 | ||
with: | ||
path: /tmp/.buildx-cache | ||
key: ${{ runner.os }}-buildx-${{ github.sha }} | ||
restore-keys: | | ||
${{ runner.os }}-buildx- | ||
- name: Cache Docker layers | ||
uses: actions/cache@v4 | ||
with: | ||
path: /tmp/.buildx-cache | ||
key: ${{ runner.os }}-buildx-${{ github.sha }} | ||
restore-keys: | | ||
${{ runner.os }}-buildx- | ||
- name: Build Docker image | ||
run: | | ||
docker buildx build --platform linux/amd64 -t sast/sast-link -f docker/Dockerfile --output type=docker,dest=image.tar . | ||
- name: Build Docker image | ||
run: | | ||
docker buildx build --platform linux/amd64 -t sast/sast-link -f docker/Dockerfile --output type=docker,dest=image.tar . | ||
- name: Copy Docker image to server | ||
uses: easingthemes/ssh-deploy@main | ||
with: | ||
- name: Copy Docker image to server | ||
uses: easingthemes/ssh-deploy@main | ||
with: | ||
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }} | ||
ARGS: "-rlgoDzvc -i --delete" | ||
SOURCE: "./image.tar" | ||
REMOTE_HOST: ${{ secrets.REMOTE_HOST }} | ||
REMOTE_USER: ${{ secrets.REMOTE_USER }} | ||
TARGET: /tmp/image.tar | ||
|
||
- name: Deploy in server | ||
uses: appleboy/[email protected] | ||
env: | ||
WORKINGDIR: ${{ secrets.WORKINGDIR }} | ||
with: | ||
host: ${{ secrets.REMOTE_HOST }} | ||
username: ${{ secrets.REMOTE_USER }} | ||
key: ${{ secrets.SSH_PRIVATE_KEY }} | ||
script_stop: true | ||
envs: WORKINGDIR | ||
script: | | ||
### Notice: run for develop ### | ||
# Stop and remove existing container if it exists | ||
if [ "$(docker ps -aq -f name=sastlink)" ]; then | ||
docker stop sastlink | ||
docker rm sastlink | ||
fi | ||
# Remove existing image if it exists | ||
if [ "$(docker images -q sast/sast-link)" ]; then | ||
docker rmi sast/sast-link | ||
fi | ||
# Load the new image and run it | ||
# It will failed, for test | ||
docker load -i /tmp/image.tar | ||
docker run --restart always -d --name sastlink -p 8080:8080 -v $WORKINGDIR:/sastlink/config sast/sast-link | ||
- name: Deploy in server | ||
uses: appleboy/[email protected] | ||
env: | ||
WORKINGDIR: ${{ secrets.WORKINGDIR }} | ||
with: | ||
host: ${{ secrets.REMOTE_HOST }} | ||
username: ${{ secrets.REMOTE_USER }} | ||
key: ${{ secrets.SSH_PRIVATE_KEY }} | ||
script_stop: true | ||
envs: WORKINGDIR | ||
script: | | ||
### Notice: run for develop ### | ||
# Stop and remove existing container if it exists | ||
if [ "$(docker ps -aq -f name=sastlink)" ]; then | ||
docker stop sastlink | ||
docker rm sastlink | ||
fi | ||
# Remove existing image if it exists | ||
if [ "$(docker images -q sast/sast-link)" ]; then | ||
docker rmi sast/sast-link | ||
fi | ||
# Load the new image and run it | ||
# It will failed, for test | ||
docker load -i /tmp/image.tar | ||
docker run --restart always -d --name sastlink -p 8080:8080 -v $WORKINGDIR:/sastlink/config sast/sast-link | ||
- name: Send Success Message | ||
if: ${{ success() }} | ||
run: | | ||
bash ./scripts/webhook.sh \ | ||
-u "${{ github.event.pull_request.html_url }}" \ | ||
-w ${{ secrets.WEBHOOK_URL }} \ | ||
-s sastlink -c "${{ github.event.pull_request.user.login }}" -f 'success' \ | ||
-m "https://github.com/${{ github.repository }}/commit/${{ github.sha }}" | ||
- name: Send Success Message | ||
if: ${{ success() }} | ||
run: | | ||
bash ./scripts/webhook.sh \ | ||
-u "${{ github.event.pull_request.html_url }}" \ | ||
-w ${{ secrets.WEBHOOK_URL }} \ | ||
-s sastlink -c "${{ github.event.pull_request.user.login }}" -f 'success' \ | ||
-m "https://github.com/${{ github.repository }}/commit/${{ github.sha }}" | ||
- name: Send Fail Message | ||
if: ${{ failure() }} | ||
run: | | ||
bash ./scripts/webhook.sh \ | ||
-u "${{ github.event.pull_request.html_url }}" \ | ||
-w ${{ secrets.WEBHOOK_URL }} \ | ||
-s sastlink -c "${{ github.event.pull_request.user.login }}" -f 'failure' \ | ||
-m "https://github.com/${{ github.repository }}/commit/${{ github.sha }}" | ||
- name: Send Fail Message | ||
if: ${{ failure() }} | ||
run: | | ||
bash ./scripts/webhook.sh \ | ||
-u "${{ github.event.pull_request.html_url }}" \ | ||
-w ${{ secrets.WEBHOOK_URL }} \ | ||
-s sastlink -c "${{ github.event.pull_request.user.login }}" -f 'failure' \ | ||
-m "https://github.com/${{ github.repository }}/commit/${{ github.sha }}" |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.