-
Notifications
You must be signed in to change notification settings - Fork 0
137 lines (118 loc) · 4.04 KB
/
main.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
---
name: Deploy Main Branch
on:
push:
branches:
- main
tags:
- v*
concurrency:
group: ${{ github.ref }}-${{ github.workflow }}
cancel-in-progress: true
jobs:
MagaLinter:
name: MegaLinter
runs-on: ubuntu-latest
permissions:
contents: write
issues: write
pull-requests: write
steps:
# Git Checkout
- name: Checkout Code
uses: actions/checkout@v4
with:
token: ${{ secrets.PAT || secrets.GITHUB_TOKEN }}
fetch-depth: 0 # If you use VALIDATE_ALL_CODEBASE = true, you can remove this line to improve performances
# MegaLinter
- name: MegaLinter
id: ml
# You can override MegaLinter flavor used to have faster performances
# More info at https://megalinter.io/latest/flavors/
uses: oxsecurity/megalinter@latest
env:
# All available variables are described in documentation
# https://megalinter.io/latest/configuration/
VALIDATE_ALL_CODEBASE: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }} # Validates all source when push on main, else just the git diff with main. Override with true if you always want to lint all sources
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# ADD YOUR CUSTOM ENV VARIABLES HERE OR DEFINE THEM IN A FILE .mega-linter.yml AT THE ROOT OF YOUR REPOSITORY
# DISABLE: COPYPASTE,SPELL # Uncomment to disable copy-paste and spell checks
# Upload MegaLinter artifacts
- name: Archive production artifacts
if: success() || failure()
uses: actions/upload-artifact@v4
with:
name: MegaLinter reports
path: |
megalinter-reports
mega-linter.log
Project-Build:
needs: MagaLinter
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v4
- name: Setup Java
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: 21
cache: gradle
- name: Build with Gradle
run: ./gradlew build --no-daemon --build-cache
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_REGISTRY_USERNAME }}
password: ${{ secrets.DOCKER_REGISTRY_TOKEN }}
- name: Build and Push Docker image
uses: docker/build-push-action@v6
if: ${{ contains(github.ref, 'ref/tags/') }}
with:
build-args: |
JAR_FILE=build/libs/*.jar
cache-from: type=gha
cache-to: type=gha,mode=max
push: true
tags: |
commongroundproject/backend:stage
commongroundproject/backend:${{ github.sha }}
context: .
- name: Build and Push Docker image
uses: docker/build-push-action@v6
if: ${{ !(contains(github.ref, 'ref/tags/')) }}
with:
build-args: |
JAR_FILE=build/libs/*.jar
cache-from: type=gha
cache-to: type=gha,mode=max
push: true
tags: |
commongroundproject/backend:dev
commongroundproject/backend:${{ github.sha }}
context: .
Deploy:
needs: [Project-Build, MagaLinter]
runs-on: [self-hosted, linux]
steps:
- name: Checkout sources
uses: actions/checkout@v4
- name: Set up SSH
run: |
mkdir -p ~/.ssh
echo '${{ secrets.DEV_DEPLOY_PRIVATE_KEY }}' >> ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
- name: Deploy Dev
if: ${{ !(contains(github.ref, 'ref/tags/')) }}
run: |
export MODE='Dev'
ssh -o SendEnv=MODE -i ~/.ssh/id_rsa [email protected]
- name: Deploy Stage
if: ${{ (contains(github.ref, 'ref/tags/')) }}
run: |
export MODE='Stage'
ssh -o SendEnv=MODE -i ~/.ssh/id_rsa [email protected]
- name: Clear up
run: rm ~/.ssh/id_rsa