Skip to content

Commit ee78556

Browse files
authored
Merge pull request #109 from KiraCore/feature/ci-cd-v2
feature/ci-cd-v2 -> release/v0.2.12
2 parents 70de3e3 + 5fd9e19 commit ee78556

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

100 files changed

+25980
-1250
lines changed

.github/workflows/branch.yml

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
name: Create version branch & PR <working>/* -> version
2+
3+
on:
4+
push:
5+
branches: [ feature/*, bugfix/* ]
6+
7+
jobs:
8+
auto-pr:
9+
name: Automated Master Branch PR
10+
runs-on: ubuntu-20.04
11+
permissions:
12+
contents: write
13+
packages: write
14+
id-token: write
15+
pull-requests: write
16+
steps:
17+
# Work around https://github.com/actions/checkout/issues/760
18+
- name: Add safe.directory
19+
run: |
20+
git config --global --add safe.directory /github/workspace
21+
git config --global --add safe.directory $PWD
22+
# ref.: https://github.com/actions/checkout, v3.0.0
23+
- name: Checkout repository
24+
uses: actions/checkout@a12a3943b4bdde767164f792f33f40b04645d846
25+
- name: Extract branch name on pull request
26+
shell: bash
27+
run: |
28+
set -x
29+
git branch -r -l
30+
echo "(current dir): $PWD" && ls -l ./
31+
chmod -Rv 555 ./scripts
32+
RELEASE_VER=$(./scripts/version.sh) && echo "RELEASE_VER=$RELEASE_VER" >> $GITHUB_ENV
33+
RELEASE_BRANCH="release/$RELEASE_VER" && echo "RELEASE_BRANCH=$RELEASE_BRANCH" >> $GITHUB_ENV
34+
REPOSITORY_NAME="${{ github.event.repository.name }}" && echo "REPOSITORY_NAME=$REPOSITORY_NAME" >> $GITHUB_ENV
35+
echo "SOURCE_BRANCH=$(echo ${GITHUB_REF#refs/heads/})" >> $GITHUB_ENV
36+
echo "DEFAULT_BRANCH=${{ github.event.repository.default_branch }}" >> $GITHUB_ENV
37+
echo "MASTER_REF=$(git ls-remote https://github.com/kiracore/$REPOSITORY_NAME | head -1 | sed 's/HEAD//')" >> $GITHUB_ENV
38+
git ls-remote https://github.com/kiracore/$REPOSITORY_NAME | egrep -q "refs/tags/${RELEASE_VER}$" && echo "RELEASE_EXISTS=true" >> $GITHUB_ENV || echo "RELEASE_EXISTS=false" >> $GITHUB_ENV
39+
( git show-branch "origin/$RELEASE_BRANCH" || git show-branch "remotes/origin/$RELEASE_BRANCH" ) && echo "TARGET_BRANCH_EXISTS=true" >> $GITHUB_ENV || echo "TARGET_BRANCH_EXISTS=false" >> $GITHUB_ENV
40+
- name: Print debug data before publishing
41+
run: |
42+
echo "Repository name: ${{ env.REPOSITORY_NAME }}"
43+
echo " Source branch: ${{ env.SOURCE_BRANCH }}"
44+
echo " Default branch: ${{ env.DEFAULT_BRANCH }}"
45+
echo " Master refer.: ${{ env.MASTER_REF }}"
46+
echo "Release version: ${{ env.RELEASE_VER }}"
47+
echo " Release branch: ${{ env.RELEASE_BRANCH }}"
48+
echo " Release exists: ${{ env.RELEASE_EXISTS }}"
49+
echo " Event name: ${{ github.event_name }}"
50+
echo " Target Exists: ${{ env.TARGET_BRANCH_EXISTS }}"
51+
# ref.: https://github.com/peterjgrainger/action-create-branch, v2.2.0
52+
- name: Create version branch from master
53+
uses: peterjgrainger/action-create-branch@c2800a3a9edbba2218da6861fa46496cf8f3195a
54+
if: |
55+
( env.TARGET_BRANCH_EXISTS == false || env.TARGET_BRANCH_EXISTS == 'false' ) &&
56+
( env.RELEASE_EXISTS == false || env.RELEASE_EXISTS == 'false' ) &&
57+
( startsWith(env.RELEASE_BRANCH, 'release/v') && contains(env.RELEASE_BRANCH, '.') )
58+
env:
59+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
60+
with:
61+
branch: ${{ env.RELEASE_BRANCH }}
62+
sha: ${{ env.MASTER_REF }}
63+
- name: Create PR from feature to version branch
64+
# ref. repo-sync/pull-request is broken, using cea2aj/pull-request instead
65+
uses: cea2aj/pull-request@84eb0c3478f13651e5649367941b867ca02d7926
66+
if: |
67+
( env.TARGET_BRANCH_EXISTS == false || env.TARGET_BRANCH_EXISTS == 'false' ) &&
68+
( env.RELEASE_EXISTS == false || env.RELEASE_EXISTS == 'false' ) &&
69+
( startsWith(env.RELEASE_BRANCH, 'release/v') && contains(env.RELEASE_BRANCH, '.') )
70+
with:
71+
github_token: ${{ secrets.REPO_ACCESS }}
72+
source_branch: ${{ env.SOURCE_BRANCH }}
73+
destination_branch: ${{ env.RELEASE_BRANCH}}
74+
pr_title: "${{ env.SOURCE_BRANCH }} -> ${{ env.RELEASE_BRANCH }}"
75+
pr_label: "kira-automation"
76+
pr_allow_empty: true

.github/workflows/main.yml

Lines changed: 420 additions & 0 deletions
Large diffs are not rendered by default.

.github/workflows/master.yml

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
name: v*.*.* -PR-> master
1+
name: release/v*.*.* -PR-> master
22

33
on:
44
push:
5-
branches: [ v*.*.* ]
5+
branches: [ v*.*.*, release/v*.*.* ]
66

77
# git ls-remote <URL> | head -1 | sed "s/HEAD//"
88
jobs:
@@ -16,26 +16,36 @@ jobs:
1616
id-token: write
1717
pull-requests: write
1818
steps:
19+
# Work around https://github.com/actions/checkout/issues/760
20+
- name: Add safe.directory
21+
run: |
22+
git config --global --add safe.directory /github/workspace
23+
git config --global --add safe.directory $PWD
24+
# ref.: https://github.com/actions/checkout, v3.0.0
25+
- name: Checkout repository
26+
uses: actions/checkout@a12a3943b4bdde767164f792f33f40b04645d846
1927
- name: Extract branch name on pull request
2028
shell: bash
2129
run: |
22-
echo "SOURCE_BRANCH=$(echo ${GITHUB_REF#refs/heads/} | tr / -)" >> $GITHUB_ENV
30+
set -x
31+
git branch -r -l
32+
echo "SOURCE_BRANCH=$(echo ${GITHUB_REF#refs/heads/})" >> $GITHUB_ENV
33+
echo "DEFAULT_BRANCH=${{ github.event.repository.default_branch }}" >> $GITHUB_ENV
2334
- name: Print debug data before publishing
2435
run: |
25-
echo "Source branch: ${{ env.SOURCE_BRANCH }}"
26-
echo " Event name: ${{ github.event_name }}"
27-
echo " Repo. name: ${{ github.event.repository.name }}"
28-
# ref.: https://github.com/actions/checkout, v3.0.0
29-
- name: Checkout repository
30-
uses: actions/checkout@a12a3943b4bdde767164f792f33f40b04645d846
36+
echo " Source branch: ${{ env.DEFAULT_BRANCH }}"
37+
echo "Default branch: ${{ env.SOURCE_BRANCH }}"
38+
echo " Event name: ${{ github.event_name }}"
39+
echo " Repo. name: ${{ github.event.repository.name }}"
3140
- name: Create PR from a version branch to master after version branch push
32-
if: startsWith(env.SOURCE_BRANCH, 'v') && contains(env.SOURCE_BRANCH, '.') && !contains(env.SOURCE_BRANCH, '-') && !contains(env.SOURCE_BRANCH, 'rc')
33-
uses: repo-sync/pull-request@5ba2c80b97c87b9174c1548141b7acd80f6376e1
41+
# ref. repo-sync/pull-request is broken, using cea2aj/pull-request instead
42+
uses: cea2aj/pull-request@84eb0c3478f13651e5649367941b867ca02d7926
43+
if: startsWith(env.SOURCE_BRANCH, 'release/v') && contains(env.SOURCE_BRANCH, '.')
3444
with:
3545
github_token: ${{ secrets.REPO_ACCESS }}
3646
source_branch: ${{ env.SOURCE_BRANCH }}
37-
destination_branch: ${{ github.event.repository.default_branch }}
38-
pr_title: "${{ env.SOURCE_BRANCH }} -> ${{ github.event.repository.default_branch }}"
47+
destination_branch: ${{ env.DEFAULT_BRANCH}}
48+
pr_title: "${{ env.SOURCE_BRANCH }} -> ${{ env.DEFAULT_BRANCH }}"
3949
pr_label: "kira-automation"
4050
pr_assignee: "asmodat"
4151
pr_allow_empty: true

.github/workflows/spam.yml

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: Clean spam PRs
22

33
on:
44
pull_request:
5-
branches: [ master, dev, latest, v*.*.*, feature/*, bugfix/* ]
5+
branches: [ master, dev, latest, v*.*.*, release/v*.*.*, feature/*, bugfix/* ]
66

77
jobs:
88
# isolate signing & repo cloning from docker image
@@ -18,6 +18,11 @@ jobs:
1818
REF_BRANCH: ${{ github.event.pull_request.head.ref }}
1919
BASE_REF_BRANCH: ${{ github.base_ref }}
2020
steps:
21+
# Work around https://github.com/actions/checkout/issues/760
22+
- name: Add safe.directory
23+
run: |
24+
git config --global --add safe.directory /github/workspace
25+
git config --global --add safe.directory $PWD
2126
# ref.: https://github.com/actions/checkout, v3.0.0
2227
- name: Checkout repository
2328
uses: actions/checkout@a12a3943b4bdde767164f792f33f40b04645d846
@@ -26,9 +31,16 @@ jobs:
2631
- name: Extract branch name & release version
2732
shell: bash
2833
run: |
29-
echo "RELEASE_VER=$(grep -Fn -m 1 'Release: ' ./RELEASE.md | rev | cut -d ":" -f1 | rev | xargs | tr -dc '[:alnum:]\-\.' || echo '')" >> $GITHUB_ENV
30-
echo "SOURCE_BRANCH=$(echo ${{ env.REF_BRANCH }} | tr / -)" >> $GITHUB_ENV
31-
echo "DESTINATION_BRANCH=$(echo ${{ env.BASE_REF_BRANCH }} | tr / -)" >> $GITHUB_ENV
34+
chmod -Rv 555 ./scripts
35+
VERSION_REGEX="^(v?)([0-9]+)\.([0-9]+)\.([0-9]+)(-?)([a-zA-Z]+)?(\.?([0-9]+)?)$"
36+
REPOSITORY_NAME=${{ github.event.repository.name }}
37+
RELEASE_VER=$(./scripts/version.sh) && echo "RELEASE_VER=$RELEASE_VER" >> $GITHUB_ENV
38+
RELEASE_BRANCH="release/$RELEASE_VER" && echo "RELEASE_BRANCH=$RELEASE_BRANCH" >> $GITHUB_ENV
39+
SOURCE_BRANCH="$(echo ${{ env.REF_BRANCH }})" && echo "SOURCE_BRANCH=$SOURCE_BRANCH" >> $GITHUB_ENV
40+
DESTINATION_BRANCH="$(echo ${{ env.BASE_REF_BRANCH }})" && echo "DESTINATION_BRANCH=$DESTINATION_BRANCH" >> $GITHUB_ENV
41+
git ls-remote https://github.com/kiracore/$REPOSITORY_NAME | egrep -q "refs/tags/${RELEASE_VER}$" && echo "RELEASE_EXISTS=true" >> $GITHUB_ENV || echo "RELEASE_EXISTS=false" >> $GITHUB_ENV
42+
[[ "$SOURCE_BRANCH" =~ $VERSION_REGEX ]] && echo "SOURCE_VERSIONED=true" >> $GITHUB_ENV || echo "SOURCE_VERSIONED=false" >> $GITHUB_ENV
43+
[[ "$DESTINATION_BRANCH" =~ $VERSION_REGEX ]] && echo "DESTINATION_VERSIONED=true" >> $GITHUB_ENV || echo "DESTINATION_VERSIONED=false" >> $GITHUB_ENV
3244
- name: Print debug data before publishing
3345
run: |
3446
echo "Source branch name: ${{ env.SOURCE_BRANCH }}"
@@ -38,31 +50,43 @@ jobs:
3850
uses: dessant/repo-lockdown@0b093279a77b44bbc38e85089b5463dd06b4aea4
3951
if: |
4052
( env.DESTINATION_BRANCH == 'master' || env.DESTINATION_BRANCH == 'dev' || env.DESTINATION_BRANCH == 'latest' ) &&
41-
( !startsWith(env.SOURCE_BRANCH, 'v') && !contains(env.SOURCE_BRANCH, '.') )
53+
( !startsWith(env.SOURCE_BRANCH, 'release/v') && !contains(env.SOURCE_BRANCH, '.') )
4254
with:
4355
pr-labels: 'invalid'
4456
pr-comment: >
4557
This repository does not accept pull requests from non version branches
46-
close-pr: true
58+
59+
--- Please CLOSE this PR after acknowledging the issue ---
60+
close-pr: false
61+
lock-pr: true
62+
pr-lock-reason: 'spam'
4763
- name: Reject invalid PRs to version branches that do NOT originate from feature/* or debug/*
4864
# ref.: https://github.com/dessant/repo-lockdown
4965
uses: dessant/repo-lockdown@0b093279a77b44bbc38e85089b5463dd06b4aea4
5066
if: |
51-
( startsWith(env.DESTINATION_BRANCH, 'v') && contains(env.DESTINATION_BRANCH, '.') ) &&
67+
( startsWith(env.DESTINATION_BRANCH, 'release/v') && contains(env.DESTINATION_BRANCH, '.') ) &&
5268
( !startsWith(env.SOURCE_BRANCH, 'feature') && !startsWith(env.SOURCE_BRANCH, 'bugfix') )
5369
with:
5470
pr-labels: 'invalid'
5571
pr-comment: >
5672
This repository does not accept pull requests from feature/* & bugfix/* branches
57-
close-pr: true
73+
74+
--- Please CLOSE this PR after acknowledging the issue ---
75+
close-pr: false
76+
lock-pr: true
77+
pr-lock-reason: 'spam'
5878
- name: Reject invalid PRs to version branches with invalid RELEASE files
5979
# ref.: https://github.com/dessant/repo-lockdown
6080
uses: dessant/repo-lockdown@0b093279a77b44bbc38e85089b5463dd06b4aea4
6181
if: |
62-
( startsWith(env.DESTINATION_BRANCH, 'v') && contains(env.DESTINATION_BRANCH, '.') ) &&
63-
( env.DESTINATION_BRANCH != env.RELEASE_VER )
82+
( startsWith(env.DESTINATION_BRANCH, 'release/v') && contains(env.DESTINATION_BRANCH, '.') ) &&
83+
( env.DESTINATION_BRANCH != env.RELEASE_BRANCH )
6484
with:
6585
pr-labels: 'invalid'
6686
pr-comment: >
67-
The release version (${{ env.RELEASE_VER }}) in the ./RELEASE.md file does NOT match the branch name (${{ env.DESTINATION_BRANCH }})
68-
close-pr: false
87+
The release version (${{ env.RELEASE_VER }}) does NOT match the branch name (${{ env.DESTINATION_BRANCH }})
88+
89+
--- Please CLOSE this PR after acknowledging the issue ---
90+
close-pr: false
91+
lock-pr: true
92+
pr-lock-reason: 'spam'

.gitignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
bin/
2+
*/bin
3+
nfpm_*
4+
*/nfpm_*
5+
*-tmp
6+
*/*-tmp
7+
*/.build
8+
*/dist
9+
*/spec
10+
*/__pycache__

DEVME.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# tools
2+
KIRA Tools
3+
4+
## Dependencies
5+
6+
```
7+
VERSION="v0.0.8.0" && cd /tmp && rm -fv ./bash-utils.sh && \
8+
CHECKSUM="1cfb806eec03956319668b0a4f02f2fcc956ed9800070cda1870decfe2e6206e" && \
9+
wget https://github.com/KiraCore/tools/releases/download/$VERSION/bash-utils.sh -O ./bash-utils.sh && \
10+
FILE_HASH=$(sha256sum ./bash-utils.sh | awk '{ print $1 }' | xargs || echo -n "") && \
11+
[ "$FILE_HASH" == "$CHECKSUM" ] && chmod -v 555 ./bash-utils.sh && \
12+
./bash-utils.sh bashUtilsSetup "/var/kiraglob" && . /etc/profile && \
13+
bash-utils loadGlobEnvs && utils echoInfo "SUCCESS: bash-utils $(bash-utils bashUtilsVersion) were installed!" || \
14+
echo "ERROR: Invalid checksum '$FILE_HASH' or bashUtilsSetup failed"
15+
```
16+
17+
## Build
18+
19+
```
20+
# set env variable to your local repos (will vary depending on the user)
21+
setGlobEnv TOOLS_REPO "/mnt/c/Users/asmodat/Desktop/KIRA/GITHUB/tools"
22+
23+
cd $TOOLS_REPO
24+
25+
make build
26+
```

Makefile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.PHONY: test build publish
2+
3+
test:
4+
./scripts/test.sh
5+
6+
build:
7+
./scripts/build.sh
8+
9+
publish:
10+
./scripts/publish.sh

README.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,46 @@
11
# tools
22
KIRA Network - useful tools & scripts
3+
4+
## Signatures
5+
6+
All files in KIRA repositories are always signed with [cosign](https://github.com/sigstore/cosign/releases)
7+
8+
Cosign requires simple initial setup of the signer keys described more precisely [here](https://dev.to/n3wt0n/sign-your-container-images-with-cosign-github-actions-and-github-container-registry-3mni)
9+
10+
```bash
11+
# install cosign
12+
COSIGN_VERSION="v1.7.2" && \
13+
if [[ "$(uname -m)" == *"ar"* ]] ; then ARCH="arm64"; else ARCH="amd64" ; fi && echo $ARCH && \
14+
PLATFORM=$(uname) && FILE=$(echo "cosign-${PLATFORM}-${ARCH}" | tr '[:upper:]' '[:lower:]') && \
15+
wget https://github.com/sigstore/cosign/releases/download/${COSIGN_VERSION}/$FILE && chmod +x -v ./$FILE && \
16+
mv -fv ./$FILE /usr/local/bin/cosign && cosign version
17+
18+
# save KIRA public cosign key
19+
cat > ./cosign.pub << EOL
20+
-----BEGIN PUBLIC KEY-----
21+
MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE/IrzBQYeMwvKa44/DF/HB7XDpnE+
22+
f+mU9F/Qbfq25bBWV2+NlYMJv3KvKHNtu3Jknt6yizZjUV4b8WGfKBzFYw==
23+
-----END PUBLIC KEY-----
24+
EOL
25+
26+
# download desired files and the corresponding .sig file from: https://github.com/KiraCore/tools/releases
27+
28+
# verify signature of downloaded files
29+
cosign verify-blob --key=./cosign.pub --signature=./<file>.sig ./<file>
30+
```
31+
32+
## bash-utils
33+
34+
KIRA bash-utils is a general purpose tool for simplifying scripts & commands
35+
36+
```bash
37+
# one line install
38+
TOOLS_VERSION="v0.2.7" && mkdir -p /usr/keys && FILE_NAME="bash-utils.sh" && \
39+
if [ -z "$KIRA_COSIGN_PUB" ] ; then KIRA_COSIGN_PUB=/usr/keys/kira-cosign.pub ; fi && \
40+
echo -e "-----BEGIN PUBLIC KEY-----\nMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE/IrzBQYeMwvKa44/DF/HB7XDpnE+\nf+mU9F/Qbfq25bBWV2+NlYMJv3KvKHNtu3Jknt6yizZjUV4b8WGfKBzFYw==\n-----END PUBLIC KEY-----" > $KIRA_COSIGN_PUB && \
41+
wget "https://github.com/KiraCore/tools/releases/download/$TOOLS_VERSION/${FILE_NAME}" -O ./$FILE_NAME && \
42+
wget "https://github.com/KiraCore/tools/releases/download/$TOOLS_VERSION/${FILE_NAME}.sig" -O ./${FILE_NAME}.sig && \
43+
cosign verify-blob --key="$KIRA_COSIGN_PUB" --signature=./${FILE_NAME}.sig ./$FILE_NAME && \
44+
chmod -v 555 ./$FILE_NAME && ./$FILE_NAME bashUtilsSetup "/var/kiraglob" && . /etc/profile && \
45+
echoInfo "Installed bash-utils $(bashUtilsVersion)"
46+
```

RELEASE.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Features:
2+
* Added `strLength, strStartsWith, strEndsWith, setTomlVar` to bash-utils
3+
4+
5+

bash-utils/Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.PHONY: test
2+
3+
test:
4+
./scripts/test.sh
5+

bash-utils/README.md

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
1-
# KIRA Bash Utils
1+
## KIRA Bash Utils
22

33
The ultimate collection of various bash-shell function to make access to various system components fast and simple from the CLI level
44

55

6-
# Install
6+
### Local Setup
77
```
8-
cd /tmp && read -p "Input branch name: " BRANCH && \
9-
wget https://raw.githubusercontent.com/KiraCore/tools/$BRANCH/bash-utils/install.sh -O ./i.sh && \
10-
chmod 555 ./i.sh && ./i.sh "$BRANCH" "/var/kiraglob" && . /etc/profile || echo "ERROR: Failed kira bash-utils installation"
8+
./bash-utils.sh utilsSetup "/var/kiraglob"
9+
```
10+
11+
### Remote Setup
12+
```
13+
cd /tmp && rm -fv ./bash-utils.sh && \
14+
wget https://raw.githubusercontent.com/KiraCore/tools/latest/bash-utils/bash-utils.sh -O ./bash-utils.sh && \
15+
chmod -v 555 ./bash-utils.sh && ./bash-utils.sh bashUtilsSetup "/var/kiraglob"
1116
```

0 commit comments

Comments
 (0)