Skip to content

Commit

Permalink
Merge pull request #6 from EveryUniv/fix/CD
Browse files Browse the repository at this point in the history
Update dev_cd.yml
  • Loading branch information
gutanbug authored Oct 5, 2023
2 parents 5fa45e4 + a68127b commit 2dd0e92
Showing 1 changed file with 85 additions and 16 deletions.
101 changes: 85 additions & 16 deletions .github/workflows/dev_cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,99 @@
# This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-gradle

name:
name: Dev_CD

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
branches: [ "dev_deploy" ]

permissions:
contents: read

jobs:
check_repo:
runs-on: ubuntu-latest
outputs:
cd-skip: ${{ steps.check_repo.outputs.cd-skip-value }}
steps:
- uses: actions/checkout@v3
- name: Check Repo
run: |
if [ "$GITHUB_REPOSITORY" != "YOUR_USER/YOUR_REPO_NAME" ]; then
echo 'cd-skip-value=true' >> $GITHUB_OUTPUT
else
echo 'cd-skip-value=false' >> $GITHUB_OUTPUT
fi
skip_cd:
needs: check_repo
if: github.repository != 'EveryUniv/next-student-council-backend'
runs-on: ubuntu-latest
steps:
- name: Skip CD
run: |
echo "CD will be terminated soon..."
exit 0
build:

runs-on: ubuntu-latest

if: github.repository == 'EveryUniv/next-student-council-backend'
needs: check_repo
environment: dev
steps:
- uses: actions/checkout@v3
- name: Set up JDK 11
uses: actions/setup-java@v3
with:
java-version: '11'
distribution: 'temurin'
- name: Build with Gradle
uses: gradle/gradle-build-action@bd5760595778326ba7f1441bcf7e88b49de61a25 # v2.6.0
with:
arguments: build
- uses: actions/checkout@v3

- name: Set up JDK 11
uses: actions/setup-java@v3
with:
java-version: '11'
distribution: 'adopt'

- name: Make test properties
env:
PROPERTIES: ${{ secrets.PROPERTIES_TEST }}
run: |
mkdir -p ./src/test/resources && cd "$_"
touch ./application.yml
echo $PROPERTIES | base64 --decode > application.yml
shell: bash

- name: Gradle Init
run: gradle init

- name: Build with Gradle
uses: gradle/gradle-build-action@bd5760595778326ba7f1441bcf7e88b49de61a25 # v2.6.0
with:
arguments: build
gradle-version: '7.6'

- name: Docker build
env:
USERNAME: ${{ secrets.DOCKER_USERNAME }}
REPO: ${{ secrets.DOCKER_REPO }}
run: |
docker build -t $USERNAME/$REPO:${GITHUB_SHA::7} -t $USERNAME/$REPO:latest .
- name: Docker push
env:
USERNAME: ${{ secrets.DOCKER_USERNAME }}
PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
REPO: ${{ secrets.DOCKER_REPO }}
run: |
docker login -u $USERNAME -p $PASSWORD
docker push $USERNAME/$REPO:${GITHUB_SHA::7}
docker push $USERNAME/$REPO:latest
- name: SSH Remote Commands
uses: appleboy/ssh-action@master
env:
REPO: ${{ secrets.DOCKER_REPO }}
with:
host: ${{ secrets.SERVER_HOST }}
username: ubuntu
key: ${{ secrets.NEXT_PRIVATE_PEM_KEY }}
envs: GITHUB_SHA,REPO
script: |
./deploy.sh ${{ secrets.DOCKER_USERNAME }} $REPO ${GITHUB_SHA::7}

0 comments on commit 2dd0e92

Please sign in to comment.