Skip to content

Merge pull request #82 from gutanbug/dev #33

Merge pull request #82 from gutanbug/dev

Merge pull request #82 from gutanbug/dev #33

Workflow file for this run

# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
# 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: Dev_CD
on:
push:
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 != 'gutanbug/renew-sw-mentoring'
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 == 'gutanbug/renew-sw-mentoring'
needs: check_repo
environment: dev
steps:
- uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
- 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/actions/setup-gradle@417ae3ccd767c252f5661f1ace9f835f9654f2b5 # v3.1.0
with:
arguments: build
gradle-version: '8.5'
- 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.MENTORING_PEM_KEY }}
envs: GITHUB_SHA,REPO
script: |
./deploy.sh ${{ secrets.DOCKER_USERNAME }} $REPO ${GITHUB_SHA::7}