Skip to content

Commit

Permalink
chore(ci): Update CI from template [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
GitLab CI committed Feb 14, 2024
1 parent 922a1d5 commit eebe532
Show file tree
Hide file tree
Showing 13 changed files with 118 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .ci/awk/check-diff.awk
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ BEGIN {
}
{
exit 1
}
}
51 changes: 51 additions & 0 deletions .ci/awk/get-deps.awk
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
function append_variable(name, value) {
if (variables[name] != "") {
variables[name] = variables[name] "," value
} else {
variables[name] = value
}
}

BEGIN {
# "," separated
variables["pkgnames"]=""
variables["dependencies"]=""
in_pkgbase=0
}

/^\tprovides = / {
if (match($0, /^\tprovides = ([a-zA-Z0-9_-]+)(=.*)?$/, o)) {
append_variable("pkgnames", o[1])
}
}

/^pkgname = / {
in_pkgbase=0
if (match($0, /^pkgname = ([a-zA-Z0-9_-]+)$/, o)) {
append_variable("pkgnames", o[1])
}
}

/^pkgbase = / {
in_pkgbase=1
}

/^\tdepends = / {
if (in_pkgbase) {
if (match($0, /^\tdepends = ([a-zA-Z0-9_-]+)([>=<].*)?$/, o)) {
append_variable("dependencies", o[1])
}
}
}

/^\tmakedepends = / {
if (in_pkgbase) {
if (match($0, /^\tmakedepends = ([a-zA-Z0-9_-]+)([>=<].*)?$/, o)) {
append_variable("dependencies", o[1])
}
}
}

END {
print variables["pkgnames"] " " variables["dependencies"]
}
2 changes: 1 addition & 1 deletion .ci/awk/remove-checksum.awk
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ function check_sum(sum) {
next
}
print
}
}
2 changes: 1 addition & 1 deletion .ci/awk/update-pkgbuild.awk
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,4 @@ function update_source(source) {
update_source($0)
}
print
}
}
2 changes: 1 addition & 1 deletion .ci/awk/update-srcinfo.awk
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ BEGIN {
}
}
}
1
1
4 changes: 2 additions & 2 deletions .ci/create-pr.sh
Original file line number Diff line number Diff line change
Expand Up @@ -129,14 +129,14 @@ function manage_branch() {
# Not up to date
git reset --hard "origin/$target_branch"
git checkout stash -- "$pkgbase"
git commit -m "chore($1): PKGBUILD modified [deploy $pkgbase]"
git commit -m "chore($1): PKGBUILD modified"
git push --force-with-lease origin "$CHANGE_BRANCH"
fi
else
# Branch does not exist, let's create it
git switch -C "$branch" "origin/$target_branch"
git checkout stash -- "$pkgbase"
git commit -m "chore($1): PKGBUILD modified [deploy $pkgbase]"
git commit -m "chore($1): PKGBUILD modified"
git push --force-with-lease origin "$CHANGE_BRANCH"
fi
git stash drop
Expand Down
6 changes: 4 additions & 2 deletions .ci/on-schedule.sh
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ function update_from_gitlab_tag() {
local COMMIT_URL VERSION
COMMIT_URL="$(jq -r '.[0].commit.web_url' <<<"$TAG_OUTPUT")"
VERSION="$(jq -r '.[0].name' <<<"$TAG_OUTPUT")"

if [ -z "$COMMIT_URL" ] || [ -z "$VERSION" ]; then
echo "ERROR: $pkgbase: Failed to get latest tag." >&2
return
Expand Down Expand Up @@ -268,7 +268,8 @@ for package in "${PACKAGES[@]}"; do
git add .
if [ "$COMMIT" == "false" ]; then
COMMIT=true
git commit -m "chore(packages): update packages [skip ci]"
[ -v GITLAB_CI ] && git commit -m "chore(packages): update packages"
[ -v GITHUB_ACTIONS ] && git commit -m "chore(packages): update packages [skip ci]"
else
git commit --amend --no-edit
fi
Expand All @@ -291,5 +292,6 @@ if [ "$COMMIT" = true ]; then
for branch in "${DELETE_BRANCHES[@]}"; do
git_push_args+=(":$branch")
done
[ -v GITLAB_CI ] && git_push_args+=("-o" "ci.skip")
git push --atomic origin HEAD:main +refs/tags/scheduled "${git_push_args[@]}"
fi
25 changes: 24 additions & 1 deletion .ci/schedule-packages.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,36 @@ elif [ -v GITHUB_ACTIONS ]; then
echo "Warning: Pipeline updates are not supported on GitHub Actions yet."
fi

function generate_deptree() {
declare -a ALL_PACKAGES
UTIL_GET_PACKAGES ALL_PACKAGES
local deptree=""

for i in "${ALL_PACKAGES[@]}"; do
local PKGNAMES DEPS
if [ -f "$i/.SRCINFO" ]; then
local AWK_OUTPUT
if ! AWK_OUTPUT=$(awk -f .ci/awk/get-deps.awk "$i/.SRCINFO"); then
continue
fi
read -r PKGNAMES DEPS <<<"$AWK_OUTPUT"
fi
if [ -n "$deptree" ]; then
deptree+=";"
fi
deptree+="$i:$PKGNAMES:$DEPS"
done
echo "$deptree"
}

if [ "$COMMAND" == "schedule" ]; then
PARAMS+=("--deptree")
PARAMS+=("$(generate_deptree)")
# Prepend the source repo name to each package name and push to PARAMS
for i in "${!PACKAGES[@]}"; do
PARAMS+=("${BUILD_REPO}:${PACKAGES[$i]}")
done
elif [ "$COMMAND" == "auto-repo-remove" ]; then
# Prepend the source repo name to each package name and push to PARAMS
PARAMS+=("${PACKAGES[@]}")
fi

Expand Down
26 changes: 22 additions & 4 deletions .ci/update-template.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,39 @@ set -x

CURRENT_REV="$(git rev-parse --abbrev-ref HEAD)"

# CI specific stuff
if [ -v GITLAB_CI ]; then
CI_RSYNC_ARGS=("--include" ".gitlab-ci.yml")
CI_COMMIT_MSG=("-m" "chore(ci): update CI from template")
CI_PUSH_ARGS=("-o" "ci.skip")
elif [ -v GITHUB_ACTIONS ]; then
CI_RSYNC_ARGS=("--include" ".github"
"--include" ".github/workflows"
"--include" ".github/workflows/chaotic-on-commit.yml"
"--include" ".github/workflows/chaotic-on-schedule.yml")
CI_COMMIT_MSG=("-m" "chore(ci): update CI from template [skip ci]")
fi

git clone --depth=1 "$TEMPLATE_REPO" "$TMPDIR/template" -b "main"

trap "git reset --hard $CURRENT_REV" ERR

rsync -a --delete --include ".gitlab-ci.yml" --include ".github" --include ".github/workflows" --include ".github/workflows/chaotic-on-schedule.yml" --include ".github/workflows/chaotic-on-commit.yml" --exclude ".ci/config" --include ".ci/***" --exclude "*" "$TMPDIR/template/" .
# Generic template files
rsync -a --delete --exclude ".ci/config" \
--include ".ci/***" \
"${CI_RSYNC_ARGS[@]}" \
--exclude "*" \
"$TMPDIR/template/" .

if ! git diff --exit-code --quiet; then
git add .
git commit -m "chore(ci): Update CI from template [skip ci]"
git commit "${CI_COMMIT_MSG[@]}"
# Check if the scheduled tag does not exist or scheduled does not point to HEAD. In which case, the scheduled tag will not be pushed
if ! [ "$(git tag -l "scheduled")" ] || [ "$(git rev-parse HEAD^)" != "$(git rev-parse scheduled)" ]; then
git push --atomic origin HEAD:main
git push --atomic origin HEAD:main "${CI_PUSH_ARGS[@]}"
else
git tag -f scheduled
git push --atomic origin HEAD:main +refs/tags/scheduled
git push --atomic origin HEAD:main +refs/tags/scheduled "${CI_PUSH_ARGS[@]}"
fi
exit 0
fi
Expand Down
2 changes: 1 addition & 1 deletion .ci/util.shlib
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ function UTIL_FETCH_AUR_TIMESTAMPS() {
if [ ${#pkgbases[@]} -eq 0 ]; then
return 0
fi

local API_URL="https://aur.archlinux.org/rpc/v5/info"
local first=1

Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/chaotic-on-commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ env:
# Controls when the workflow will run
on:
push:
branches: [ "main" ]
branches: ["main"]

concurrency:
group: chaotic
Expand All @@ -28,6 +28,7 @@ jobs:
id: process
run: |
.ci/on-commit.sh
# shellcheck disable=SC2129
if [ -f .ci/schedule-params.txt ]; then
params="$(cat .ci/schedule-params.txt)"
echo "SCHEDULE_PARAMS<<SCHEDULE_PARAMS_EOF" >> "$GITHUB_OUTPUT"
Expand All @@ -53,4 +54,4 @@ jobs:
REDIS_PASSWORD: ${{ secrets.REDIS_PASSWORD }}
DEPLOY_KEY: ${{ secrets.DEPLOY_KEY }}
if: ${{ needs.process.outputs.SCHEDULE_PARAMS != '' }}
timeout-minutes: 5
timeout-minutes: 5
3 changes: 2 additions & 1 deletion .github/workflows/chaotic-on-schedule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ env:
on:
schedule:
# Hourly
- cron: '0 * * * *'
- cron: "0 * * * *"
# Manually
workflow_dispatch:

Expand All @@ -35,6 +35,7 @@ jobs:
id: process
run: |
.ci/on-schedule.sh
# shellcheck disable=SC2129
if [ -f .ci/schedule-params.txt ]; then
params="$(cat .ci/schedule-params.txt)"
echo "SCHEDULE_PARAMS<<SCHEDULE_PARAMS_EOF" >> "$GITHUB_OUTPUT"
Expand Down
8 changes: 5 additions & 3 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@ default:
- git remote set-url origin $REPO_URL
- git fetch --tags --all --depth 20

include: ".gitlab-ci-*.yml"

on-commit:
stage: process
image: alpine:latest
script:
- .ci/on-commit.sh
artifacts:
paths:
- .ci/schedule-params.txt
- .ci/schedule-params.txt
expire_in: 1 hour
resource_group: chaotic
rules:
Expand All @@ -30,7 +32,7 @@ on-schedule:
- .ci/on-schedule.sh
artifacts:
paths:
- .ci/schedule-params.txt
- .ci/schedule-params.txt
expire_in: 1 hour
resource_group: chaotic
rules:
Expand All @@ -48,4 +50,4 @@ do-schedule:
script:
- if [ -f .ci/schedule-params.txt ]; then set -x; source ".ci/schedule-params.txt"; if [[ -v PARAMS_SCHEDULE ]]; then /entry_point.sh "${PARAMS_SCHEDULE[@]}"; fi; if [[ -v PARAMS_AUTOREPOREMOVE ]]; then /entry_point.sh "${PARAMS_AUTOREPOREMOVE[@]}"; fi; fi
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH

0 comments on commit eebe532

Please sign in to comment.