Skip to content

Commit c6de209

Browse files
committed
2 parents 46a3871 + eb4b6eb commit c6de209

File tree

5 files changed

+108
-49
lines changed

5 files changed

+108
-49
lines changed

.github/dependabot.yml

Lines changed: 24 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -10,48 +10,31 @@ updates:
1010
target-branch: "main"
1111
open-pull-requests-limit: 10
1212
labels: ["dependencies", "npm", "frontend"]
13-
# CHỈ chặn nâng major Angular (v21+), vẫn cho phép 20.x
1413
ignore:
1514
- dependency-name: "@angular/*"
1615
update-types: ["version-update:semver-major"]
1716
groups:
1817
angular-core:
19-
patterns:
20-
- "@angular/*"
21-
- "zone.js"
18+
patterns: ["@angular/*", "zone.js"]
2219
update-types: ["minor", "patch"]
2320
tooling-and-tests:
24-
patterns:
25-
- "typescript"
26-
- "karma*"
27-
- "jasmine*"
28-
- "@types/*"
29-
- "cypress"
21+
patterns: ["typescript","karma*","jasmine*","@types/*","cypress"]
3022
update-types: ["minor", "patch"]
3123
ui-and-md:
32-
patterns:
33-
- "highlight.js"
34-
- "marked"
35-
- "github-markdown-css"
36-
- "apexcharts"
37-
- "ng-apexcharts"
38-
- "ngx-*"
24+
patterns: ["highlight.js","marked","github-markdown-css","apexcharts","ng-apexcharts","ngx-*"]
3925
update-types: ["minor", "patch"]
4026
codemirror-suite:
41-
patterns:
42-
- "codemirror"
43-
- "@codemirror/*"
27+
patterns: ["codemirror","@codemirror/*"]
4428
update-types: ["minor", "patch"]
4529

46-
4730
# GitHub Actions
4831
- package-ecosystem: "github-actions"
4932
directory: "/"
5033
schedule:
5134
interval: "weekly"
5235
day: "monday"
53-
time: "03:00"
54-
timezone: "Asia/Bangkok"
36+
time: "03:00"
37+
timezone: "Asia/Bangkok"
5538
target-branch: "main"
5639
labels: ["dependencies", "github-actions"]
5740
open-pull-requests-limit: 10
@@ -67,18 +50,28 @@ updates:
6750
target-branch: "main"
6851
labels: ["dependencies", "docker"]
6952
open-pull-requests-limit: 10
53+
registries:
54+
- dockerhub
55+
- ghcr
7056
groups:
7157
nginx-node-base:
72-
patterns:
73-
- "nginx"
74-
- "node"
58+
patterns: ["nginx","node"]
7559
update-types: ["minor", "patch"]
7660
dotnet-base:
77-
patterns:
78-
- "mcr.microsoft.com/dotnet/*"
61+
patterns: ["mcr.microsoft.com/dotnet/*"]
7962
update-types: ["minor", "patch"]
8063
jre-maven:
81-
patterns:
82-
- "eclipse-temurin:*"
83-
- "maven:*"
64+
patterns: ["eclipse-temurin:*","maven:*"]
8465
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)