Skip to content

Commit 3bb76aa

Browse files
committed
2 parents 34649fa + b7d6455 commit 3bb76aa

File tree

5 files changed

+133
-29
lines changed

5 files changed

+133
-29
lines changed

.github/dependabot.yml

Lines changed: 49 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,77 @@
11
version: 2
22
updates:
3-
# NPM (Angular app)
3+
# (Angular app)
44
- package-ecosystem: "npm"
55
directory: "/"
66
schedule:
77
interval: "daily"
88
time: "02:00"
99
timezone: "Asia/Bangkok"
10-
open-pull-requests-limit: 10
1110
target-branch: "main"
12-
labels: ["dependencies", "npm"]
13-
allow:
14-
- dependency-type: "direct"
15-
- dependency-type: "all"
11+
open-pull-requests-limit: 10
12+
labels: ["dependencies", "npm", "frontend"]
1613
ignore:
17-
# ví dụ giữ cố định major của Angular 19
1814
- dependency-name: "@angular/*"
19-
versions: [">=20"]
15+
update-types: ["version-update:semver-major"]
16+
groups:
17+
angular-core:
18+
patterns: ["@angular/*", "zone.js"]
19+
update-types: ["minor", "patch"]
20+
tooling-and-tests:
21+
patterns: ["typescript","karma*","jasmine*","@types/*","cypress"]
22+
update-types: ["minor", "patch"]
23+
ui-and-md:
24+
patterns: ["highlight.js","marked","github-markdown-css","apexcharts","ng-apexcharts","ngx-*"]
25+
update-types: ["minor", "patch"]
26+
codemirror-suite:
27+
patterns: ["codemirror","@codemirror/*"]
28+
update-types: ["minor", "patch"]
2029

2130
# GitHub Actions
2231
- package-ecosystem: "github-actions"
2332
directory: "/"
2433
schedule:
2534
interval: "weekly"
2635
day: "monday"
27-
time: "03:00"
28-
timezone: "Asia/Bangkok"
36+
time: "03:00"
37+
timezone: "Asia/Bangkok"
38+
target-branch: "main"
2939
labels: ["dependencies", "github-actions"]
40+
open-pull-requests-limit: 10
3041

31-
# Docker base images (Nginx, Node…)
42+
# Docker images (Nginx, Node…)
3243
- package-ecosystem: "docker"
3344
directory: "/docker"
3445
schedule:
3546
interval: "weekly"
3647
day: "tuesday"
3748
time: "04:00"
3849
timezone: "Asia/Bangkok"
50+
target-branch: "main"
3951
labels: ["dependencies", "docker"]
52+
open-pull-requests-limit: 10
53+
registries:
54+
- dockerhub
55+
- ghcr
56+
groups:
57+
nginx-node-base:
58+
patterns: ["nginx","node"]
59+
update-types: ["minor", "patch"]
60+
dotnet-base:
61+
patterns: ["mcr.microsoft.com/dotnet/*"]
62+
update-types: ["minor", "patch"]
63+
jre-maven:
64+
patterns: ["eclipse-temurin:*","maven:*"]
65+
update-types: ["minor", "patch"]
66+
67+
registries:
68+
dockerhub:
69+
type: docker-registry
70+
url: https://index.docker.io/v1/
71+
username: ${{secrets.DOCKERHUB_USER}}
72+
password: ${{secrets.DOCKERHUB_TOKEN}}
73+
ghcr:
74+
type: docker-registry
75+
url: https://ghcr.io
76+
username: ${{secrets.GHCR_USERNAME}}
77+
password: ${{secrets.GHCR_TOKEN}}

.github/workflows/ci-sonar-angular.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ on:
1212
- "sonar-project.properties"
1313
pull_request:
1414

15+
###
1516
permissions:
1617
contents: read
1718
pull-requests: write
@@ -31,7 +32,7 @@ jobs:
3132
fetch-depth: 0 # Sonar cần full history để tính blame
3233

3334
- name: Set up JDK (for Sonar scanner)
34-
uses: actions/setup-java@v4
35+
uses: actions/setup-java@v5
3536
with:
3637
distribution: temurin
3738
java-version: "21"
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Dependabot Auto-merge
2+
3+
on:
4+
pull_request_target:
5+
types: [opened, synchronize, reopened, ready_for_review]
6+
7+
permissions:
8+
contents: write
9+
pull-requests: write
10+
11+
jobs:
12+
automerge:
13+
if: github.actor == 'dependabot[bot]'
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- name: Fetch Dependabot metadata
18+
id: meta
19+
uses: dependabot/fetch-metadata@v2
20+
with:
21+
github-token: ${{ secrets.GITHUB_TOKEN }}
22+
23+
- name: Auto-approve patch/minor
24+
if: |
25+
steps.meta.outputs.update-type == 'version-update:semver-patch' ||
26+
steps.meta.outputs.update-type == 'version-update:semver-minor'
27+
uses: hmarr/auto-approve-action@v4
28+
with:
29+
github-token: ${{ secrets.GITHUB_TOKEN }}
30+
31+
- name: Enable PR auto-merge (squash) for patch/minor
32+
if: |
33+
steps.meta.outputs.update-type == 'version-update:semver-patch' ||
34+
steps.meta.outputs.update-type == 'version-update:semver-minor'
35+
uses: peter-evans/enable-pull-request-automerge@v3
36+
with:
37+
token: ${{ secrets.GITHUB_TOKEN }}
38+
pull-request-number: ${{ github.event.pull_request.number }}
39+
merge-method: squash

.github/workflows/deploy-frontend.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,14 +106,20 @@ jobs:
106106
fi
107107
}
108108
109-
# docker login (nếu có)
109+
# docker login Docker Hub (nếu có)
110110
if [ -n "${DOCKERHUB_USER:-}" ] && [ -n "${DOCKERHUB_TOKEN:-}" ]; then
111111
echo "docker login Docker Hub..."
112112
echo "$DOCKERHUB_TOKEN" | docker login -u "$DOCKERHUB_USER" --password-stdin
113113
else
114114
echo "Thiếu DOCKERHUB_USER/DOCKERHUB_TOKEN trong .env (image public thì vẫn OK)."
115115
fi
116116
117+
# docker login GHCR (nếu có)
118+
if [ -n "${GHCR_USERNAME:-}" ] && [ -n "${GHCR_TOKEN:-}" ]; then
119+
echo "docker login GHCR..."
120+
echo "$GHCR_TOKEN" | docker login ghcr.io -u "$GHCR_USERNAME" --password-stdin
121+
fi
122+
117123
echo "Pull image frontend tag ${IMAGE_TAG}…"
118124
compose -f docker-compose.prod-frontend.yml --env-file .env pull
119125

.github/workflows/frontend-docker-publish.yml

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ permissions:
2020

2121
env:
2222
DOCKER_REPO: ${{ secrets.DOCKERHUB_USER }}/codecampus-frontend
23+
GHCR_OWNER: ${{ github.repository_owner }}
2324
DOCKERFILE_PATH: docker/angular-frontend.Dockerfile
2425
PLATFORMS: linux/amd64
2526

@@ -28,40 +29,59 @@ jobs:
2829
runs-on: ubuntu-latest
2930

3031
steps:
31-
- name: Checkout
32-
uses: actions/checkout@v4
32+
- uses: actions/checkout@v4
3333

34-
- name: Set up QEMU
35-
uses: docker/setup-qemu-action@v3
34+
- uses: docker/setup-qemu-action@v3
35+
- uses: docker/setup-buildx-action@v3
3636

37-
- name: Set up Buildx
38-
uses: docker/setup-buildx-action@v3
39-
40-
- name: Derive tags
37+
- name: Derive tags (Docker Hub + GHCR)
4138
id: meta
39+
shell: bash
4240
run: |
43-
TAGS=""
41+
set -euo pipefail
42+
43+
# Hạ lowercase owner (an toàn POSIX)
44+
OWNER_LC="$(printf '%s' "${GHCR_OWNER}" | tr '[:upper:]' '[:lower:]')"
45+
echo "OWNER_LC=${OWNER_LC}" >> "$GITHUB_ENV"
46+
4447
if [ "${GITHUB_REF_TYPE}" = "tag" ]; then
4548
VERSION="${GITHUB_REF_NAME#v}"
46-
echo "IMAGE_TAG=${VERSION}" >> $GITHUB_ENV
47-
TAGS="${{ env.DOCKER_REPO }}:${VERSION}"
49+
echo "IMAGE_TAG=${VERSION}" >> "$GITHUB_ENV"
50+
HUB="${DOCKER_REPO}:${VERSION}"
51+
GHCR="ghcr.io/${OWNER_LC}/codecampus-frontend:${VERSION}"
4852
else
4953
SHA_TAG="${GITHUB_SHA::12}"
50-
echo "IMAGE_TAG=${SHA_TAG}" >> $GITHUB_ENV
51-
TAGS="${{ env.DOCKER_REPO }}:${SHA_TAG}"
54+
echo "IMAGE_TAG=${SHA_TAG}" >> "$GITHUB_ENV"
55+
HUB="${DOCKER_REPO}:${SHA_TAG}"
56+
GHCR="ghcr.io/${OWNER_LC}/codecampus-frontend:${SHA_TAG}"
5257
if [ "${GITHUB_REF_NAME}" = "main" ]; then
53-
TAGS="${TAGS},${{ env.DOCKER_REPO }}:latest"
58+
HUB="${HUB}"$'\n'"${DOCKER_REPO}:latest"
59+
GHCR="${GHCR}"$'\n'"ghcr.io/${OWNER_LC}/codecampus-frontend:latest"
5460
fi
5561
fi
56-
echo "tags=${TAGS}" >> $GITHUB_OUTPUT
62+
63+
# Xuất output "tags" dạng đa dòng
64+
{
65+
echo "tags<<__TAGS__"
66+
printf '%s\n' "$HUB"
67+
printf '%s\n' "$GHCR"
68+
echo "__TAGS__"
69+
} >> "$GITHUB_OUTPUT"
5770
5871
- name: Login to Docker Hub
5972
uses: docker/login-action@v3
6073
with:
6174
username: ${{ secrets.DOCKERHUB_USER }}
6275
password: ${{ secrets.DOCKERHUB_TOKEN }}
6376

64-
- name: Build & Push
77+
- name: Login to GHCR
78+
uses: docker/login-action@v3
79+
with:
80+
registry: ghcr.io
81+
username: ${{ github.actor }}
82+
password: ${{ secrets.GITHUB_TOKEN }}
83+
84+
- name: Build & Push (Docker Hub + GHCR)
6585
uses: docker/build-push-action@v6
6686
with:
6787
context: .

0 commit comments

Comments
 (0)