Skip to content

Build and Release

Build and Release #35

name: Build and Release
on:
push:
branches:
- main
workflow_dispatch:
inputs:
logLevel:
description: 'Log level'
required: true
default: 'warning'
type: choice
options:
- info
- warning
- debug
tags:
description: 'Test scenario tags'
required: false
type: boolean
environment:
description: 'Environment to run tests against'
type: environment
required: true
description:
description: 'Release description'
required: true
type: string
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.x
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y libncurses5-dev
pip install -r requirements.txt
- name: Get latest release tag
id: get_latest_tag
run: |
latest_tag=$(git describe --tags --abbrev=0 2>/dev/null)
if [ -z "$latest_tag" ]; then
echo "First attempt failed. Trying again..."
latest_tag=$(git describe --tags --abbrev=0)
fi
echo "Latest tag: $latest_tag"
echo "::set-output name=tag::$latest_tag"
continue-on-error: true
- name: Increment version
id: increment_version
run: |
current_tag=${{ steps.get_latest_tag.outputs.tag }}
version_parts=(${current_tag//./ })
new_version="${version_parts[0]}.${version_parts[1]}.$((version_parts[2]+1))"
echo "::set-output name=next_version::${new_version}"
- name: List changed files
run: |
echo "Changed files:"
git diff --name-only ${{ github.event.before }} ${{ github.sha }}
- name: Ask for description
id: ask_for_description
run: echo "::set-output name=description::${{ inputs.description }}"
- name: Build executable
run: |
pyinstaller --onefile main.py
mv ./dist/main ./dist/CWA_Linux
- name: Create or Update Release
id: create_or_update_release
run: |
tag_name=${{ steps.get_latest_tag.outputs.tag }}
release_name="Release $tag_name"
release_id=$(curl -s -H "Authorization: token ${{ secrets.GH_TOKEN }}" "https://api.github.com/repos/${{ github.repository }}/releases/tags/$tag_name" | jq -r '.id // empty')
if [ -z "$release_id" ]; then
# Create a new release
response=$(curl -s -H "Authorization: token ${{ secrets.GH_TOKEN }}" -d '{"tag_name":"'"$tag_name"'","name":"'"$release_name"'","draft":false,"prerelease":false, "body":"'"${{ steps.ask_for_description.outputs.description }}"'"}' "https://api.github.com/repos/${{ github.repository }}/releases")
release_id=$(echo "$response" | jq -r '.id')
fi
echo "::set-output name=release_id::$release_id"
shell: bash
- name: Upload Release Asset
id: upload-release-asset
uses: actions/upload-release-asset@v1
with:
upload_url: https://uploads.github.com/repos/${{ github.repository }}/releases/${{ steps.create_or_update_release.outputs.release_id }}/assets{?name,label}
asset_path: ./dist/CWA_Linux
asset_name: Console-Weather-App
asset_content_type: application/octet-stream
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
- name: Cleanup
run: rm -r build