Some corner cases and tests #102
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 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: CI/CD | |
on: | |
push: | |
branches: [ "main" ] | |
permissions: | |
contents: read | |
env: | |
MONGO_PASSWORD: ${{ secrets.MONGO_PASSWORD }} | |
TELEGRAM_USERNAME: ${{ secrets.TELEGRAM_USERNAME }} | |
TELEGRAM_TOKEN: ${{ secrets.TELEGRAM_TOKEN }} | |
jobs: | |
test: | |
name: Testing | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
fetch-depth: '0' | |
- name: Run Tests | |
uses: ./.github/actions/testing | |
analysis: | |
name: Analysis | |
runs-on: ubuntu-latest | |
needs: test | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
fetch-depth: '0' | |
- name: Run Analysis | |
uses: ./.github/actions/analysis | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
sonar-token: ${{ secrets.SONAR_TOKEN }} | |
version: | |
name: Versioning | |
permissions: write-all | |
runs-on: ubuntu-latest | |
needs: analysis | |
outputs: | |
new_tag: ${{ steps.bump_version.outputs.new_tag }} | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
fetch-depth: '0' | |
- name: Bump version and push tag | |
id: bump_version | |
uses: anothrNick/github-tag-action@1.61.0 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
DEFAULT_BUMP: patch | |
build: | |
name: Building | |
needs: version | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
fetch-depth: '0' | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v3 | |
with: | |
java-version: 17 | |
distribution: 'temurin' | |
- name: Build with Gradle | |
uses: gradle/gradle-build-action@67421db6bd0bf253fb4bd25b31ebb98943c375e1 | |
with: | |
arguments: build -x test | |
- name: Build and Push Docker Image | |
uses: mr-smithers-excellent/docker-build-push@v5 | |
with: | |
image: ${{ secrets.DOCKER_USERNAME }}/odmiana | |
tags: ${{ needs.version.outputs.new_tag }} | |
registry: docker.io | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
deploy: | |
name: Deploying | |
needs: [version, build] | |
runs-on: ubuntu-latest | |
steps: | |
- name: Deploy to AWS EC2 | |
uses: appleboy/ssh-action@v0.1.8 | |
with: | |
host: ${{ secrets.AWS_HOST }} | |
username: ${{ secrets.SSH_USERNAME }} | |
key: ${{ secrets.SSH_PRIVATE_KEY }} | |
script: | | |
docker login | |
docker pull ${{ secrets.DOCKER_USERNAME }}/odmiana:${{ needs.version.outputs.new_tag }} | |
docker stop odmiana | |
docker rm odmiana | |
docker run --detach --name odmiana --network ec2-user_odmiana_network \ | |
-e MONGO_HOST \ | |
-e MONGO_USERNAME \ | |
-e MONGO_PASSWORD \ | |
-e TELEGRAM_USERNAME \ | |
-e TELEGRAM_TOKEN \ | |
-e OWNER_ID \ | |
-e VERSION=${{ needs.version.outputs.new_tag }} \ | |
-p 8080:8080 \ | |
${{ secrets.DOCKER_USERNAME }}/odmiana:${{ needs.version.outputs.new_tag }} |