Skip to content

Commit

Permalink
Merge pull request #11 from catenasys/fix/correct-update-repo-tag
Browse files Browse the repository at this point in the history
ci: update stadard build patterns
  • Loading branch information
scealiontach authored Jul 8, 2021
2 parents 32d3ef3 + 4bc5282 commit 3ffd275
Show file tree
Hide file tree
Showing 5 changed files with 468 additions and 56 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
dist
build
markers
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ repos:
rev: v1.1.10
hooks:
- id: forbid-tabs
exclude: "^(Makefile|.*.go)$"
exclude: "^(Makefile|.*.mk|.*.go)$"
- repo: git://github.com/doublify/pre-commit-go
rev: 208a4aaa7f86b44e961eaaea526743b920e187a0
hooks:
Expand Down
80 changes: 41 additions & 39 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -47,61 +47,63 @@ pipeline {

stage('Build') {
steps {
sh 'make clean all'
sh 'make clean build'
}
}

stage('Publish') {
stage('Package') {
steps {
withCredentials([
usernamePassword(credentialsId: 'btp-build-nexus',
usernameVariable:'USER',
passwordVariable:'PASSWORD')]) {
sh '''
for f in $(find dist -name '*.tar.gz' ); do
job_base_name=$(dirname "$JOB_NAME")
base=$(basename $f)
sh "make package"
}
}

if [ "$BRANCH_NAME" = "main" ]; then
curl -u "$USER:$PASSWORD" --upload-file $f \
${PUBLISH_BASE_URL}/${job_base_name}/$base
else
curl -u "$USER:$PASSWORD" --upload-file $f \
${PUBLISH_BASE_URL}/${job_base_name}/$base
fi
done
stage("Analyze") {
steps {
withCredentials([string(credentialsId: 'fossa.full.token', variable: 'FOSSA_API_KEY')]) {
sh '''
make analyze
'''
}
}
}

stage('Create Archives') {
stage('Test') {
steps {
sh '''
REPO=$(git remote show -n origin | grep Fetch | awk -F'[/.]' '{print $6}')
VERSION=`git describe --dirty`
git archive HEAD --format=zip -9 --output=$REPO-$VERSION.zip
git archive HEAD --format=tgz -9 --output=$REPO-$VERSION.tgz
'''
archiveArtifacts artifacts: '**/*.zip'
archiveArtifacts artifacts: '**/*.tgz'
sh "make test"
}
}

}

post {
always {
sh 'make clean || true '
}
success {
echo "Build success"
stage('Create Archive') {
steps {
sh "make archive"
archiveArtifacts 'build/*.tgz, build/*.zip'
}
aborted {
error "Aborted, exiting now"
}

stage("Publish") {
when {
expression { env.BRANCH_NAME == "main" }
}
failure {
error "Failed, exiting now"
steps {
withCredentials([string(credentialsId: 'btp-build-github-pat',
variable: 'GITHUB_TOKEN')]) {
sh '''
make clean publish
'''
}
}
}
}

post {
success {
echo "Successfully completed"
}
aborted {
error "Aborted, exiting now"
}
failure {
error "Failed, exiting now"
}
}
}
36 changes: 20 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,22 +1,35 @@
MAKEFILE_DIR := $(dir $(lastword $(MAKEFILE_LIST)))
include $(MAKEFILE_DIR)/standard_defs.mk

VERSION := $(shell git describe --dirty |cut -c2-)
all: package

clean:
rm -rf dist

package: package_scripts

publish: package gh-create-draft-release
if [ "$(RELEASABLE)" = "yes" ];then \
$(GH_RELEASE) upload $(VERSION) dist/*.tgz; \
fi

.PHONY: package_scripts
package_scripts: dist/doc-$(VERSION).tar.gz dist/bin-$(VERSION).tar.gz dist/lib-$(VERSION).tar.gz

.PHONY: all
all: dist

dist/doc-$(VERSION).tar.gz:
mkdir -p dist/doc/bash
for inc in $$(find bash -name \*.sh); do \
mdname=$$(echo $$inc | sed -e 's/\.sh/\.md/') ; \
bash/bashadoc $$inc > dist/doc/$$mdname ; done
mdname=$$(echo $$inc | sed -e 's/\.sh/\.md/') ; \
bash/bashadoc $$inc > dist/doc/$$mdname ; done
tar -zcf dist/doc-$(VERSION).tar.gz -C dist doc
rm -rf dist/doc

dist/bin-$(VERSION).tar.gz:
mkdir -p dist/bin
for s in $$(find bash -type f -exec grep -q "includer" {} \; -print|grep -v ".sh$$"); do \
base=$$(basename $$s) ; \
bash/pack-script -v -f $$s -o dist/bin/$$base ; \
base=$$(basename $$s) ; \
bash/pack-script -v -f $$s -o dist/bin/$$base ; \
done
tar -zcf dist/bin-$(VERSION).tar.gz -C dist bin
rm -rf dist/bin
Expand All @@ -26,12 +39,3 @@ dist/lib-$(VERSION).tar.gz:
cp bash/*.sh dist/lib
tar -zcf dist/lib-$(VERSION).tar.gz -C dist lib
rm -rf dist/lib

.PHONY: clean
clean:
rm -rf dist

.PHONY: test

.PHONY: dist
dist: dist/doc-$(VERSION).tar.gz dist/bin-$(VERSION).tar.gz dist/lib-$(VERSION).tar.gz
Loading

0 comments on commit 3ffd275

Please sign in to comment.