Skip to content

Merge pull request #740 from prancer-io/development #174

Merge pull request #740 from prancer-io/development

Merge pull request #740 from prancer-io/development #174

Workflow file for this run

name: build and publish PRANCER BASIC
on:
push:
branches:
- master
jobs:
build:
name: build and publish
runs-on: ubuntu-latest
steps:
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Set up Python 3.8
uses: actions/setup-python@v2
with:
python-version: "3.8"
- name: Checkout code
uses: actions/checkout@v2
with:
repository: prancer-io/cloud-validation-framework
ref: master
token: ${{ secrets.GIT_TOKEN }}
- name: testing
run: |
# docker run --rm -v $(pwd):$(pwd) -w=$(pwd) python:3.6.8 sh dev-test.sh
docker run --rm -v $(pwd):$(pwd) -w=$(pwd) python:3.8 sh dev-test.sh
docker run --rm -v $(pwd):$(pwd) -w=$(pwd) python:3.9 sh dev-test.sh
- name: install SO dependencies
run: |
sudo apt-get install jq
- name: python_build
run: |
pip install wheel
python setup.py sdist bdist_wheel
- name: read_version
id: read_version
run: |
VERSION=$(cat setup.py | grep version=)
echo $VERSION > output
sed -i "s/'//g" output
sed -i 's/"//g' output
sed -i 's/,//g' output
sed -i 's/version=//g' output
sed -i 's/\n//g' output
VERSION=$(cat output | tr -d '\n')
echo Application version $VERSION
echo ::set-output name=VERSION::$VERSION
- name: create_tag
run: |
TAG=V${{ steps.read_version.outputs.VERSION }}
PAYLOAD="{ \"tag_name\": \"${TAG}\", \"target_commitish\": \"${{ github.event.inputs.branch }}\", \"name\": \"${TAG}\", \"body\": \"Release: ${TAG}\", \"draft\": false, \"prerelease\": false }"
echo "https://api.github.com/repos/prancer-io/cloud-validation-framework/releases/tags/${TAG}"
RESPONSE_CODE=$(curl -s -o /dev/null -w "%{http_code}" https://api.github.com/repos/prancer-io/cloud-validation-framework/releases/tags/${TAG})
echo "Reponse code ${RESPONSE_CODE} for TAG: ${TAG}"
#if [[ $RESPONSE_CODE == "404" ]]; then
echo "Tag not found. Creating it"
echo $PAYLOAD >> payload.json
echo "Content $(cat payload.json)"
curl -H "Authorization: token ${{ secrets.GIT_TOKEN }}" \
-H "User-Agent: token Github-actions" \
-X POST \
https://api.github.com/repos/prancer-io/cloud-validation-framework/releases \
-d @payload.json > response.json
UPLOAD_URL=$(cat response.json | jq -r .upload_url)
echo $UPLOAD_URL > output
sed -i "s/{?name,label}//g" output
UPLOAD_URL=$(cat output)
echo "Upload URL $UPLOAD_URL"
cd dist
ls -lt ./ | awk '{print $5,$9}' > output
c=`cat <<EOF
import os
file1 = open('output', 'r')
lines = file1.readlines()
count = 0
for line in lines:
if line.strip() != "":
lineSplit = line.split(" ")
token="${{ secrets.GIT_TOKEN }}"
agent="Github-actions"
fileName=lineSplit[1].replace("\n", "")
size=lineSplit[0].replace("\n", "")
uploadUrl="$UPLOAD_URL"
print("token " + token + " fileName " + fileName + " size " + size + " uploadUrl " + uploadUrl )
curlOperation = "curl -X POST --data-binary @\"{}\" -H \"Content-Length: {}\" -H \"Content-type: application/zip\" -H \"Authorization: token {}\" -H \"User-Agent: {}\" {}?name={}".format(fileName, size, token, agent, uploadUrl, fileName)
print(curlOperation)
os.system(curlOperation)
EOF`
python -c "$c"
#fi
rm output
- name: upload to pypi.org
id: twine
run: |
pip install twine
twine --version
twine upload dist/* -u ${{ secrets.PIP_USER }} -p ${{ secrets.PIP_PASSWORD }}
- name: Docker build
id: docker_build
run: |
# Wait X seconds for pypi to have the binary ready
sleep 600
docker build -t prancer/prancer-basic:${{ steps.read_version.outputs.VERSION }}\
--build-arg APP_VERSION=${{ steps.read_version.outputs.VERSION }} -f dockerfiles/Dockerfile .
- name: Docker push
id: docker_push
run: |
docker login -u ${{ secrets.DOCKER_USER }} -p '${{ secrets.DOCKER_PASSWORD }}'
docker push prancer/prancer-basic:${{ steps.read_version.outputs.VERSION }}