Skip to content
This repository was archived by the owner on Jan 12, 2025. It is now read-only.

Commit f1c589d

Browse files
committed
no message
1 parent 3635e85 commit f1c589d

File tree

2 files changed

+121
-14
lines changed

2 files changed

+121
-14
lines changed

.github/workflows/github_release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: Create GitHub Release after GitLab tag mirror
33
on:
44
push:
55
tags:
6-
- '*'
6+
- '[0-9]+.[0-9]+.[0-9]+'
77

88
jobs:
99
release:

.gitlab-ci.yml

Lines changed: 120 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,21 @@ stages:
33
- release
44
- build
55

6+
services:
7+
- name: ghcr.io/griefed/gitlab-ci-cd:2.0.8
8+
alias: docker
9+
10+
workflow:
11+
rules:
12+
- if: '$CI_MERGE_REQUEST_EVENT_TYPE == "detached"'
13+
when: never
14+
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
15+
when: never
16+
- when: always
17+
618
test docker:
719
stage: test
8-
image: griefed/gitlab-ci-cd:1.0.1
9-
services:
10-
- name: docker:dind
11-
alias: docker
20+
image: ghcr.io/griefed/gitlab-ci-cd:2.0.8
1221
variables:
1322
project_name: $CI_PROJECT_NAME
1423
SEMANTIC_RELEASE_PACKAGE: $CI_PROJECT_NAME
@@ -34,10 +43,7 @@ test docker:
3443
release:
3544
needs: ['test docker']
3645
stage: release
37-
image: griefed/gitlab-ci-cd:1.0.1
38-
services:
39-
- name: docker:dind
40-
alias: docker
46+
image: ghcr.io/griefed/gitlab-ci-cd:2.0.8
4147
variables:
4248
project_name: $CI_PROJECT_NAME
4349
SEMANTIC_RELEASE_PACKAGE: $CI_PROJECT_NAME
@@ -53,10 +59,7 @@ release:
5359

5460
build:
5561
stage: build
56-
image: griefed/gitlab-ci-cd:1.0.1
57-
services:
58-
- name: docker:dind
59-
alias: docker
62+
image: ghcr.io/griefed/gitlab-ci-cd:2.0.8
6063
variables:
6164
project_name: $CI_PROJECT_NAME
6265
SEMANTIC_RELEASE_PACKAGE: $CI_PROJECT_NAME
@@ -78,4 +81,108 @@ build:
7881
--tag "index.docker.io/$DOCKERHUB_USER/$DOCKERHUB_REPO:$CI_COMMIT_TAG"
7982
--tag "index.docker.io/$DOCKERHUB_USER/$DOCKERHUB_REPO:latest" .
8083
only:
81-
- tags
84+
- tags
85+
86+
Check Packages:on-schedule:
87+
only:
88+
- schedules
89+
before_script:
90+
- |-
91+
echo "Preparing package versions comparison."
92+
# Check and, if necessary, update git user and mail
93+
if [[ "$(git config --list | grep user.name)" != "user.name=$GIT_USER" ]];then
94+
git config --global user.name $GIT_USER
95+
fi
96+
if [[ "$(git config --list | grep user.email)" != "user.email=$GIT_MAIL" ]];then
97+
git config --global user.email $GIT_MAIL
98+
fi
99+
100+
# Clean system of potentially interrupting images
101+
docker image rm -f $DOCKERHUB_USER/$DOCKERHUB_REPO:latest
102+
docker image rm -f $DOCKERHUB_REPO
103+
rm -rf /tmp/$CI_PROJECT_PATH
104+
mkdir -p /tmp/$CI_PROJECT_PATH
105+
echo "Preparations complete."
106+
script:
107+
- |-
108+
echo "Comparing package versions."
109+
# Clone the repository
110+
git clone $CI_PROJECT_URL.git /tmp/$CI_PROJECT_PATH && \
111+
cd /tmp/$CI_PROJECT_PATH && \
112+
113+
if [ ! -s "package_versions.txt" ];then
114+
echo "No package_versions.txt present. Creating..."
115+
116+
# Gather package information from latest build
117+
docker run --rm --entrypoint /bin/sh -v /tmp/$CI_PROJECT_PATH:/tmp $DOCKERHUB_USER/$DOCKERHUB_REPO:latest -c '\
118+
apt list -qq --installed > /tmp/package_versions.txt && \
119+
sort -o /tmp/package_versions.txt /tmp/package_versions.txt && \
120+
chmod 777 /tmp/package_versions.txt' && \
121+
122+
# Checkout our branch
123+
git checkout -f $CI_DEFAULT_BRANCH && \
124+
125+
wait && \
126+
127+
# Add and commit new file to repository
128+
git add package_versions.txt && \
129+
git commit -m 'chore: Add list of package versions.' && \
130+
131+
# Push the changes to the remote
132+
echo "https://***:***@$CI_SERVER_HOST/$CI_PROJECT_PATH.git"
133+
git push "https://$GIT_USER:$GITLAB_TOKEN@$CI_SERVER_HOST/$CI_PROJECT_PATH".git --all && \
134+
135+
# Nice
136+
echo "package_versions.txt added."
137+
138+
elif [ -s "package_versions.txt" ];then
139+
echo "package_versions.txt present. Comapring..."
140+
141+
# Build local image for new package versions list
142+
docker build --no-cache --tag $DOCKERHUB_REPO . && \
143+
144+
# Get packages from newly build local image
145+
docker run --rm --entrypoint /bin/sh -v /tmp/$CI_PROJECT_PATH:/tmp $DOCKERHUB_REPO -c '\
146+
apt list -qq --installed > /tmp/package_versions_new.txt && \
147+
sort -o /tmp/package_versions_new.txt /tmp/package_versions_new.txt && \
148+
chmod 777 /tmp/package_versions_new.txt' && \
149+
150+
# Get checksum of old packages
151+
OLD_CHECKSUM=$(md5sum package_versions.txt | cut -f1 -d" ") && \
152+
153+
# Get checksum of new packages
154+
NEW_CHECKSUM=$(md5sum package_versions_new.txt | cut -f1 -d" ") && \
155+
156+
# If new checksum is not the same as old checksum, we have new versions
157+
if [ "${OLD_CHECKSUM}" != "${NEW_CHECKSUM}" ]; then
158+
159+
# Checkout our branch
160+
git checkout -f $CI_DEFAULT_BRANCH && \
161+
162+
# Copy the new package versions list to repository
163+
mv -f package_versions_new.txt package_versions.txt && \
164+
165+
wait && \
166+
167+
# Add and commit new file to repository
168+
git add package_versions.txt && \
169+
git commit -m 'build: Update installed packages in Docker container.' && \
170+
171+
# Push the changes to the remote
172+
git push "https://$GIT_USER:$GITLAB_TOKEN@$CI_SERVER_HOST/$CI_PROJECT_PATH.git" --all && \
173+
174+
# Nice
175+
echo "Packages updated."
176+
else
177+
echo "No package updates available."
178+
fi
179+
180+
fi
181+
echo "Comparison complete."
182+
after_script:
183+
- |-
184+
echo "Cleaning up."
185+
docker image rm -f $DOCKERHUB_USER/$DOCKERHUB_REPO:latest
186+
docker image rm -f $DOCKERHUB_REPO
187+
rm -rf /tmp/$CI_PROJECT_PATH
188+
echo "Done."

0 commit comments

Comments
 (0)