-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
326 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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""" | ||
} | ||
} | ||
}*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters