Skip to content

Commit cbfa12a

Browse files
committed
first commit
0 parents  commit cbfa12a

File tree

6 files changed

+171
-0
lines changed

6 files changed

+171
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: My First GitHub Actions
2+
3+
on: [push]
4+
5+
jobs:
6+
build:
7+
runs-on: ubuntu-latest
8+
9+
strategy:
10+
matrix:
11+
python-version: [3.8, 3.9]
12+
13+
steps:
14+
- uses: actions/checkout@v3
15+
- name: Set up Python
16+
uses: actions/setup-python@v2
17+
with:
18+
python-version: ${{ matrix.python-version }}
19+
20+
- name: Install dependencies
21+
run: |
22+
python -m pip install --upgrade pip
23+
pip install pytest
24+
25+
- name: Run tests
26+
run: |
27+
cd src
28+
python -m pytest addition.py

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# GitHub-Actions-Zero-to-Hero
2+
Repository to kick start your journey with GitHub Actions
3+
4+
## Comparing with Jenkins
5+
6+
### Advantages of GitHub Actions over Jenkins
7+
8+
- Hosting: Jenkins is self-hosted, meaning it requires its own server to run, while GitHub Actions is hosted by GitHub and runs directly in your GitHub repository.
9+
10+
- User interface: Jenkins has a complex and sophisticated user interface, while GitHub Actions has a more streamlined and user-friendly interface that is better suited for simple to moderate automation tasks.
11+
12+
- Cost: Jenkins can be expensive to run and maintain, especially for organizations with large and complex automation needs. GitHub Actions, on the other hand, is free for open-source projects and has a tiered pricing model for private repositories, making it more accessible to smaller organizations and individual developers.
13+
14+
### Advantages of Jenkins over GitHub Actions
15+
16+
- Integration: Jenkins can integrate with a wide range of tools and services, but GitHub Actions is tightly integrated with the GitHub platform, making it easier to automate tasks related to your GitHub workflow.
17+
18+
In conclusion, Jenkins is better suited for complex and large-scale automation tasks, while GitHub Actions is a more cost-effective and user-friendly solution for simple to moderate automation needs.
19+
20+
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: End to End CI/CD workflow for Java Applicaton with Maven, Sonar and k8s Intergation
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
env:
9+
KUBECONFIG: ${{ secrets.KUBECONFIG }}
10+
SONAR_TOKEN: ${{ secrets.SONAR_TKN }}
11+
12+
jobs:
13+
build:
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- name: Checkout code
18+
uses: actions/checkout@v2
19+
20+
- name: Java jdk setup
21+
uses: actions/setup-java@v1
22+
with:
23+
java-version: 12
24+
25+
- name: maven target # change accordingly
26+
run: mvn clean install
27+
28+
- name: Perform analysis on Sonar Qube
29+
uses: sonarsource/sonarcloud-github-action@v1
30+
with:
31+
sonarcloud.organization: <name of your org>
32+
sonarcloud.projectKey: <key>
33+
sonarcloud.projectName: <name>
34+
sonarcloud.token: ${{ env.SONAR_TKN }}
35+
sonarcloud.scannerVersion: "4.2.0.1873"
36+
37+
deploy:
38+
needs: build
39+
runs-on: ubuntu-latest
40+
41+
steps:
42+
- name: Checkout code
43+
uses: actions/checkout@v2
44+
45+
- name: Deploy to k8s
46+
uses: stefanzweifel/k8s-action@v2.0.0
47+
with:
48+
args: apply -f kubernetes/
49+
env:
50+
KUBECONFIG: ${{ env.KUBECONFIG }}

examples/deploy-to-k8s.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Deploy to k8s
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
env:
9+
KUBECONFIG: ${{ secrets.KUBECONFIG }}
10+
11+
jobs:
12+
deploy:
13+
runs-on: kubernetes
14+
steps:
15+
- name: Checkout code
16+
uses: actions/checkout@v2
17+
18+
- name: Create Docker Image
19+
uses: docker/build-push-action@v2
20+
with:
21+
context: .
22+
push: true
23+
24+
- name: Deploy to k8s
25+
uses: appleboy/kubectl-action@v1.0.0
26+
with:
27+
args: apply -f deployment.yaml
28+
env:
29+
KUBECONFIG: ${{ env.KUBECONFIG }}

examples/deploy-to-swarm.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Deploy to Swarm (Docker Swarm)
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
env:
9+
DOCKER_HOST: tcp://<ip-address-of-your-swarm-manager>:2376
10+
DOCKER_REGISTRY_USER: <username>
11+
DOCKER_REGISTRY_PASS: ${{ secrets.DOCKER_REGISTRY_PASS }}
12+
13+
jobs:
14+
deploy:
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
- name: Checkout code
19+
uses: actions/checkout@v2
20+
21+
- name: Create Docker Image
22+
uses: docker/build-push-action@v2
23+
with:
24+
context: .
25+
push: true
26+
tags: <registry-username>/<image-name>:${{ env.GITHUB_SHA }}
27+
username: ${{ env.DOCKER_REGISTRY_USER }}
28+
password: ${{ env.DOCKER_REGISTRY_PASS }}
29+
30+
- name: Deploy to swarm
31+
run: |
32+
echo "$DOCKER_REGISTRY_PASS" | docker login --username "$DOCKER_REGISTRY_USER" --password-stdin
33+
docker stack deploy -c stack.yaml <stack-name>
34+
env:
35+
DOCKER_HOST: ${{ env.DOCKER_HOST }}
36+
DOCKER_TLS_CERTDIR: "/certs"

src/addition.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# app.py
2+
# This is a test commit
3+
def add(a, b):
4+
return a + b
5+
6+
def test_add():
7+
assert add(1, 2) == 3
8+
assert add(1, -1) == 0

0 commit comments

Comments
 (0)