Skip to content

Commit

Permalink
add ci job
Browse files Browse the repository at this point in the history
  • Loading branch information
samo3l committed Aug 9, 2023
1 parent d7c0c51 commit b1541ff
Show file tree
Hide file tree
Showing 8 changed files with 326 additions and 3 deletions.
168 changes: 168 additions & 0 deletions .ci/Jenkinsfile.gosh-tools-prepare-rc
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
pipeline {
agent none

options {
timestamps ()
}
parameters {
gitParameter branchFilter: 'origin/(.*)', defaultValue: 'dev', name: 'sha1', type: 'PT_BRANCH', quickFilterEnabled: true
booleanParam name: 'DRYRUN', defaultValue: true, description: 'If enabled, will NOT publish pre-release artifacts.'
//booleanParam name: 'ONLY_IMAGES', defaultValue: false, description: 'If enabled, will only build and push images.'
}

stages {
stage('Clone repository') {
agent {
docker {
image 'jenkins-docker-agent:1'
args '-v /var/run/docker.sock:/var/run/docker.sock -v /opt:/opt --group-add docker'
}
}
steps {
script {
if (env.ghprbPullLink) {
env.COMMIT = env.ghprbSourceBranch
} else {
env.COMMIT = params.sha1
}
}
echo "${COMMIT}"
git branch: "${COMMIT}", url: 'https://github.com/gosh-sh/anytree.git'
checkout scm
script {
env.APP_VERSION = sh(script: " grep -m1 version gosh/Cargo.toml | awk '{print \$NF}' | tr -d '\"' ", returnStdout: true).trim()
currentBuild.displayName = "${BUILD_NUMBER}_${COMMIT}_${APP_VERSION}"
}
}
}
stage('Build: Anytree') {
agent {
node {
label 'jenkins-main'
}
}
steps {
buildGoshCli()
}
}

stage('Build: Prepare archives') {
agent {
node {
label 'jenkins-main'
}
}
steps {
archiveAzureArtifacts()
}
}

stage('Prerelease: Anytree | binaries') {
agent {
docker {
image 'jenkins-docker-agent:1'
args '-v /var/run/docker.sock:/var/run/docker.sock -v /opt:/opt --group-add docker -v /root/jenkins-main/workspace:/tmp'
}
}
steps {
prereleaseBinaries()
}
}

/*stage('Prerelease: Images | Docker Image') {
agent {
node {
label 'jenkins-main'
}
}
steps {
retry(3) {
prereleaseToolsDeliveryImage()
}
}
}*/

}
post {
always {
node('jenkins-main') {
cleanWs()
}
}
}
}

///////////////////////////////////////////////////////////////////////////////////////////
///////////////////////FUNCTIONS//////////////////////////////////

// BUILD
def buildGoshCli() {
script {
if (!params.ONLY_IMAGES) {
dir('gosh') {
sh '''
#!/bin/bash
set -ex

# 3 = gosh
PIPELINE_3_ID=$(az pipelines build queue --definition-id 3 --branch \${COMMIT} --project gosh | jq .id)
PIPELINE_3_STATUS=inProgress

until [ \$PIPELINE_3_STATUS = "completed" ]
do
sleep 60
PIPELINE_3_STATUS=$(az pipelines build show --project gosh --id $PIPELINE_3_ID | jq .status | tr -d '\"')
done

cd ${WORKSPACE}
rm -rf linux-*

az pipelines runs artifact download --project gosh --artifact-name linux-amd64 --run-id $PIPELINE_3_ID --path linux-amd64 && sleep 2
az pipelines runs artifact download --project gosh --artifact-name linux-arm64 --run-id $PIPELINE_3_ID --path linux-arm64 && sleep 2
'''
}
}
}
}

def archiveAzureArtifacts() {
script {
if (!params.ONLY_IMAGES) {
sh '''
#!/bin/bash
set -ex

rm -rf gosh-*.tar.gz
chmod +x linux-a*/*

tar -czvf gosh-linux-amd64.tar.gz -C linux-amd64 $(ls -A linux-amd64)
tar -czvf gosh-linux-arm64.tar.gz -C linux-arm64 $(ls -A linux-arm64)
'''
}
}
}

def prereleaseBinaries() {
script {
if (!params.DRYRUN && !params.ONLY_IMAGES) {
dir('.ci/scripts') {
withCredentials([string(credentialsId: 'github-gosh-release', variable: 'TOKEN')]) {
sh './create-github-release.sh $TOKEN ${APP_VERSION} ${COMMIT}'
sh './github-upload-assets.sh $TOKEN ${APP_VERSION} /tmp/${JOB_NAME}/gosh-linux-amd64.tar.gz application/gzip'
sh './github-upload-assets.sh $TOKEN ${APP_VERSION} /tmp/${JOB_NAME}/gosh-linux-arm64.tar.gz application/gzip'
}
}
}
}
}

/*def prereleaseToolsDeliveryImage() {
script {
if (!params.DRYRUN) {
withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: 'teamgosh-dockerhub', usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD']]) {
sh 'docker login -u $USERNAME -p $PASSWORD'
}
sh """PATH=$HOME/.cargo/bin:$PATH && make gosh-ubuntu-release && make gosh-rust-release && make gosh-golang-release"""
}
}
}*/
73 changes: 73 additions & 0 deletions .ci/azure/gosh-cli-pipeline.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
variables:
- name: RUSTUP_TOOLCHAIN
value: 1.68.0

trigger: none
pr: none

strategy:
matrix:
linux:
imageName: ubuntu-20.04
binName: gosh
artifactNameAmd: linux-amd64
maxParallel: 3

pool:
vmImage: $(imageName)

steps:
#######################################################
# Pre-requirements
# Linux
- script: |
set -ex
sudo apt install -y protobuf-compiler
condition: eq( variables['Agent.OS'], 'Linux' )
displayName: Install pre-requirements Linux

###########################################################
# Rust setup
# Linux
- script: |
set -ex
curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain $RUSTUP_TOOLCHAIN
echo "##vso[task.setvariable variable=PATH;]$PATH:$HOME/.cargo/bin"
env:
RUSTUP_TOOLCHAIN: ${{ variables.RUSTUP_TOOLCHAIN }}
displayName: "Install rust (*nix)"
condition: eq( variables['Agent.OS'], 'Linux' )

##########################################################
# Build
# Linux
- script: |
set -ex
cargo build --release --bin gosh
sudo apt update -y
sudo apt install -y build-essential g++-x86-64-linux-gnu libc6-dev-amd64-cross g++-aarch64-linux-gnu libc6-dev-arm64-cross gcc-aarch64-linux-gnu
rustup target add aarch64-unknown-linux-gnu
cargo build --release --target aarch64-unknown-linux-gnu --bin gosh
env:
CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_LINKER: x86_64-linux-gnu-gcc
CC_x86_64_unknown_linux_gnu: x86_64-linux-gnu-gcc
CXX_x86_64_unknown_linux_gnu: x86_64-linux-gnu-g++
CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER: aarch64-linux-gnu-gcc
CC_aarch64_unknown_linux_gnu: aarch64-linux-gnu-gcc
CXX_aarch64_unknown_linux_gnu: aarch64-linux-gnu-g++
workingDirectory: ./
condition: eq( variables['Agent.OS'], 'Linux' )
displayName: Build Linux

##################################
# Publish
# Linux amd64
- publish: ./target/release/$(binName)
artifact: $(artifactNameAmd)
displayName: Publish amd64 Linux

# Linux arm64
- publish: ./target/aarch64-unknown-linux-gnu/release/$(binName)
artifact: linux-arm64
condition: eq( variables['Agent.OS'], 'Linux' )
displayName: Publish arm64 Linux
14 changes: 14 additions & 0 deletions .ci/scripts/create-github-release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash

set -e
set -o pipefail

TOKEN=$1
VERSION=$2
BRANCH=$3

curl -sX POST -H "Accept: application/vnd.github+json" -H "Authorization: token ${TOKEN}" \
https://api.github.com/repos/gosh-sh/gosh-build-tools/releases \
-d "{\"tag_name\":\"${VERSION}\", \"target_commitish\":\"${BRANCH}\", \
\"name\":\"Version: rc-${VERSION}\", \"body\":\"GOSH release\", \"draft\":false, \
\"prerelease\":true, \"generate_release_notes\":false}"
17 changes: 17 additions & 0 deletions .ci/scripts/github-upload-assets.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

set -e
set -o pipefail

TOKEN=$1
VERSION=$2
ASSET=$3
CONTENT_TYPE=$4

UPLOAD_URL=$(curl -sH "Authorization: token ${TOKEN}" \
"https://api.github.com/repos/gosh-sh/gosh-build-tools/releases/tags/${VERSION}" | jq -r '.upload_url' | cut -d'{' -f1)

curl -sX POST -H "Authorization: token ${TOKEN}" \
-H "Accept: application/vnd.github.v3+json" -H "Content-Type: ${CONTENT_TYPE}" \
-H "Content-Length: $(wc -c <"$ASSET" | xargs)" \
-T "$ASSET" "${UPLOAD_URL}?name=$(basename "$ASSET")" | cat
35 changes: 35 additions & 0 deletions .ci/scripts/package-deb.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/bash

PKG_NAME="git-remote-gosh"
BINARIES=("git-remote-gosh" "git-remote-gosh_v1_0_0" "git-remote-gosh_v2_0_0" "git-remote-gosh_v3_0_0" "git-remote-gosh_v4_0_0")
DISPATCHER_FILE="dispatcher.ini"
ARCHITECTURES=("amd64" "arm64")

for arch in "${ARCHITECTURES[@]}"; do
# Create necessary directories
mkdir -p "${PKG_NAME}_${arch}/DEBIAN"
mkdir -p "${PKG_NAME}_${arch}/usr/local/bin"
mkdir -p "${PKG_NAME}_${arch}/usr/local/share/git-remote-gosh"

# Copy binaries into package
for binary in "${BINARIES[@]}"; do
cp "linux-${arch}/${binary}" "${PKG_NAME}_${arch}/usr/local/bin/"
done

# Copy dispatcher.ini into package
cp "linux-${arch}/${DISPATCHER_FILE}" "${PKG_NAME}_${arch}/usr/local/bin"

# Create control file
cat << EOF > "${PKG_NAME}_${arch}/DEBIAN/control"
Package: ${PKG_NAME}
Version: 4.1.20
Section: custom
Priority: optional
Architecture: ${arch}
Maintainer: GOSH <[email protected]>
Description: Git remote helper for GOSH repositories.
EOF

# Build Debian package (binary package)
dpkg-deb --build "${PKG_NAME}_${arch}"
done
16 changes: 16 additions & 0 deletions .ci/scripts/update-github-release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash

set -e
set -o pipefail

TOKEN=$1
VERSION=$2
# shellcheck disable=SC2034 # Unused variables left for readability
BRANCH=$3

RELEASE_ID=$(curl -sH "Authorization: token ${TOKEN}" \
"https://api.github.com/repos/gosh-sh/gosh-build-tools/releases/tags/${VERSION}" | jq -r '.id' | cut -d'{' -f1)

curl -X PATCH -H "Accept: application/vnd.github+json" -H "Authorization: token ${TOKEN}" \
https://api.github.com/repos/gosh-sh/gosh/releases/"$RELEASE_ID" \
-d "{\"name\":\"Version: ${VERSION}\", \"prerelease\":false}"
2 changes: 1 addition & 1 deletion anytree-cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "anytree-cli"
version = "0.0.0"
version = "0.1.0"
edition = "2021"

[[bin]]
Expand Down
4 changes: 2 additions & 2 deletions tools/python/generate-sbom.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
SBOM_OUTPUT_PATH = 'sbom.json'
PROJECT_URL= 'https://github.com/gosh-sh/gosh.git'
PROJECT_COMMIT= '08d9325d8df759ca833a60a66fcc6b2b8c060a87'
PROJECT_SRC_PATH= 'v5_x/v5.1.0/git-remote-gosh'
PROJECT_SRC_PATH= 'v5_x/v5.1.0/git-remote-gosh' # if Cargo project is not in the repository

# Load Cargo.lock
with open(CARGO_LOCK_PATH) as f:
Expand Down Expand Up @@ -46,7 +46,7 @@
{
"vendor": "GOSH",
"name": "anytree",
"version": "0.0.0"
"version": "0.1.0"
}
],
"component": {
Expand Down

0 comments on commit b1541ff

Please sign in to comment.