From 1ba159f29485a81a48d1e0614014ea8d1b0b4032 Mon Sep 17 00:00:00 2001 From: Jorge Marques Date: Fri, 3 Oct 2025 19:47:13 +0200 Subject: [PATCH 1/5] bashrc,entrypoint.sh: move from action/v1 branch They are ci/contianer related. Signed-off-by: Jorge Marques --- README.md | 4 +++ bashrc | 84 +++++++++++++++++++++++++++++++++++++++++++++++++++ entrypoint.sh | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 171 insertions(+) create mode 100644 README.md create mode 100644 bashrc create mode 100644 entrypoint.sh diff --git a/README.md b/README.md new file mode 100644 index 0000000..75786c8 --- /dev/null +++ b/README.md @@ -0,0 +1,4 @@ +Auxiliary files for containers +============================== + +Contains reusable scripts for containers. diff --git a/bashrc b/bashrc new file mode 100644 index 0000000..915ef15 --- /dev/null +++ b/bashrc @@ -0,0 +1,84 @@ +#!/bin/bash + +it=false ; [ -z "$PS1" ] || it=true + +if git rev-parse --is-inside-work-tree > /dev/null 2>&1 ; then + pushd $(realpath $(git rev-parse --git-common-dir)/..) 1>/dev/null + + ci_worktree=$(git worktree list | grep '\[_ci\]' | cut -f1 -d " ") + if [[ -z "$ci_worktree" ]]; then + remote=$(git remote -v | grep analogdevicesinc | head -1 | cut -f1) + if [[ ! -z "$remote" ]]; then + $it && printf "Remote '\e[34m$remote\e[0m' matches '\e[34manalogdevicesinc\e[0m'." + if git ls-remote --exit-code --heads $remote refs/heads/ci 1>/dev/null ; then + $it && printf "\b, fetching branch '\e[34mci\e[0m'..." + git fetch --quiet $remote ci + git branch -D _ci &>/dev/null + git worktree add -q -b _ci _ci $remote/ci + ci_worktree=$(git worktree list | grep '\[_ci\]' | cut -f1 -d " ") + $it && printf "\33[2K\rFetched CI branch to '$ci_worktree'.\n" + $it && printf "To \e[34mclean-up\e[0m, use: \n" + $it && printf " \e[34mgit worktree remove _ci\e[0m\n\n" + fi + fi + fi + if [[ ! -z "$ci_worktree" ]]; then + if [[ -f "$ci_worktree/ci/user.sh" ]]; then + source $ci_worktree/ci/user.sh + elif [[ -f "$ci_worktree/ci/build.sh" ]]; then + source $ci_worktree/ci/build.sh + if $it; then + printf "Sourced methods from '$ci_worktree/ci/build.sh':\n\e[34m" + grep -oE '^[a-zA-Z][a-zA-Z0-9_]*\s*\(\)\s*\{' $ci_worktree/ci/build.sh | \ + awk -F'[ ()]+' '{print $1}' | column + printf "\e[0m" + fi + fi + fi + + if [[ -z "$head_sha" ]]; then + export head_sha=@ + fi + if [[ -z "$base_sha" ]]; then + export base_sha=@~6 + fi + if $it; then + printf "The git commit range was set to:\n" + printf "\$base_sha..\$head_sha: \e[34m$base_sha..$head_sha\e[0m \n" + printf "Adjust '\$base_sha' and '\$head_sha' to your work range.\n" + fi + + popd &>/dev/null +else + printf "\e[31mNot\e[0m a git repository! Won't set ci tools, nor git commit range.\n" +fi + +github_pipe_fifo=/tmp/github_env_$(tr -dc A-Za-z0-9 Date: Fri, 3 Oct 2025 20:54:28 +0200 Subject: [PATCH 2/5] bashrc: source bash_completions If interactive and available. Signed-off-by: Jorge Marques --- bashrc | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/bashrc b/bashrc index 915ef15..dc455e2 100644 --- a/bashrc +++ b/bashrc @@ -53,6 +53,12 @@ else printf "\e[31mNot\e[0m a git repository! Won't set ci tools, nor git commit range.\n" fi +if $it; then + if [ -f /usr/share/bash-completion/bash_completion ]; then + . /usr/share/bash-completion/bash_completion + fi +fi + github_pipe_fifo=/tmp/github_env_$(tr -dc A-Za-z0-9 Date: Mon, 6 Oct 2025 12:55:19 +0200 Subject: [PATCH 3/5] bashrc: remove fetch worktree Required credentials, moved to container-run.sh. Move ci/user.sh -> user.sh. Signed-off-by: Jorge Marques --- bashrc | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) diff --git a/bashrc b/bashrc index dc455e2..8ddc839 100644 --- a/bashrc +++ b/bashrc @@ -6,24 +6,8 @@ if git rev-parse --is-inside-work-tree > /dev/null 2>&1 ; then pushd $(realpath $(git rev-parse --git-common-dir)/..) 1>/dev/null ci_worktree=$(git worktree list | grep '\[_ci\]' | cut -f1 -d " ") - if [[ -z "$ci_worktree" ]]; then - remote=$(git remote -v | grep analogdevicesinc | head -1 | cut -f1) - if [[ ! -z "$remote" ]]; then - $it && printf "Remote '\e[34m$remote\e[0m' matches '\e[34manalogdevicesinc\e[0m'." - if git ls-remote --exit-code --heads $remote refs/heads/ci 1>/dev/null ; then - $it && printf "\b, fetching branch '\e[34mci\e[0m'..." - git fetch --quiet $remote ci - git branch -D _ci &>/dev/null - git worktree add -q -b _ci _ci $remote/ci - ci_worktree=$(git worktree list | grep '\[_ci\]' | cut -f1 -d " ") - $it && printf "\33[2K\rFetched CI branch to '$ci_worktree'.\n" - $it && printf "To \e[34mclean-up\e[0m, use: \n" - $it && printf " \e[34mgit worktree remove _ci\e[0m\n\n" - fi - fi - fi if [[ ! -z "$ci_worktree" ]]; then - if [[ -f "$ci_worktree/ci/user.sh" ]]; then + if [[ -f "$ci_worktree/user.sh" ]]; then source $ci_worktree/ci/user.sh elif [[ -f "$ci_worktree/ci/build.sh" ]]; then source $ci_worktree/ci/build.sh From a6d0404d327c08cc21958b4fa818f037f665c6d5 Mon Sep 17 00:00:00 2001 From: Jorge Marques Date: Mon, 6 Oct 2025 13:28:54 +0200 Subject: [PATCH 4/5] fix: entrypoint.sh: move from action/v1 branch An older version was copied over. Signed-off-by: Jorge Marques --- entrypoint.sh | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 2a31c04..bb661d9 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -15,15 +15,13 @@ unset config_flags unset name_label if [[ -z "$runner_labels_" ]]; then - runner_labels_="repo-only,v1" + runner_labels_="repo-only" fi if [[ -z "$config_flags_" ]]; then config_flags_="--replace" fi -source /usr/local/bin/github-api.sh - if [[ -z "$org_repository_" ]]; then echo "No org_repository provided" exit 1 @@ -31,10 +29,13 @@ fi function get_runner_token () { if [[ ! -z "$github_token_" ]]; then - runner_token_=$( - gh-actions-token $github_token_ \ - $org_repository_ - ) + runner_token_=$(curl -L \ + -X POST \ + -H "Accept: application/vnd.github+json" \ + -H "Authorization: Bearer $github_token_" \ + -H "X-GitHub-Api-Version: 2022-11-28" \ + "https://api.github.com/repos/$org_repository_/actions/runners/registration-token" \ + | jq -r .token) if [[ "$runner_token_" == "null" ]]; then echo "Failed to get '$org_repository_' runner_token, check github_token permission" From 4c5de1d68fcf530a1282e45fbfb930f3b7483f9a Mon Sep 17 00:00:00 2001 From: Jorge Marques Date: Fri, 10 Oct 2025 17:01:55 +0200 Subject: [PATCH 5/5] bashrc: export CI_WORKTREE Needed when using additional files from ci branch. Signed-off-by: Jorge Marques --- bashrc | 1 + 1 file changed, 1 insertion(+) diff --git a/bashrc b/bashrc index 8ddc839..2a29eb8 100644 --- a/bashrc +++ b/bashrc @@ -7,6 +7,7 @@ if git rev-parse --is-inside-work-tree > /dev/null 2>&1 ; then ci_worktree=$(git worktree list | grep '\[_ci\]' | cut -f1 -d " ") if [[ ! -z "$ci_worktree" ]]; then + export CI_WORKTREE=$ci_worktree if [[ -f "$ci_worktree/user.sh" ]]; then source $ci_worktree/ci/user.sh elif [[ -f "$ci_worktree/ci/build.sh" ]]; then