Skip to content

Commit

Permalink
Feat gh actions workflow improvements (#169)
Browse files Browse the repository at this point in the history
* feat: added a callable workflow for pytest

* feat: call pytest from the main workflow

* fix: dependency

* fix: python version reference

* feat: renamed the workflow to main.yml

* feat: move versioning to version.yml

* feat: validate versions

* feat: renamed job

* test: version validator

* feat: works, revert version

* feat: cli build workflow

* feat: use build from build.yml

* fix: added version dependency

* fix: remove dependency from build

* feat: move linux arm64 and alpine build to build.yml

* test: disable arm and apk builds

* fix: dependency

* chore: remove unused jobs

* feat: moved docker jobs to docker.yml

* test: remove trigger

* feat: set version in setup.py

* chore: added setuptools dev dependency

* feat: refactored docker file, added entrypoint, setuptools based install

* test: build

* test: run docker

* test: remove build dependency

* test: comment

* test: testbuild

* feat: added version dependency

* fix: tag

* fix: remove tag

* fix: build

* feat: add arm64 and armv6 builds

* fix: added rust and cargo dependency

* feat: revert to old Dockerfile

* feat: removed armv6

* feat: removed comments, added buildx multi arc builds

* fix: testing errors

* fix: version checks

* fix: command

* debug: version confirmation

* feat: pass version as input to docker build

* feat: pass version to docker build

* feat: added pypi build and upload

* feat: added pypi

* feat: only run docker on release creation

* chore: bump upload artifact version to v4

* feat: remove build dependency

* feat: added comment

* feat: only run pypi on release creation

* feat: added a download and test version stage

* feat: pass version to pypi

* test: pull and test version

* chore: clean up tests

* chore: bump gh actions dependencies

* feat: removed unneeded phase-alpine-build

* feat: removed unneeded phase-alpine-build asset processing

* feat: use python version from inputs

* feat: remove version artifact

* feat: added script to process assets

* feat: use process script in process-assets

* fix: .apk, .deb, .rpm hashing

* chore: remove commented code

* feat: moved process-assets job

* feat: added attach to release

* feat: added cli installation script

* fix: removed GITHUB_TOKEN from main

* fix: distro images

* fix: permission issues during installation

* fix: checksum path

* fix: rpm permissions

* feat: use checkout v4

* feat: move attach-to-release

* feat: added jobs in main

* feat: added comments

* fix: sha256 sum filenames

* feat: added arm64 linux install test

* feat: install and test the cli from pypi on a windows, mac, linux matrix

* test: matrix pypi cli install

* feat: works
  • Loading branch information
nimish-ks authored Oct 16, 2024
1 parent 37995eb commit 255c231
Show file tree
Hide file tree
Showing 15 changed files with 801 additions and 380 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/attach-to-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Attach Assets to Release

on:
workflow_call:
inputs:
version:
required: true
type: string

jobs:
attach-to-release:
name: Attach Assets to Release
runs-on: ubuntu-20.04
steps:
- name: Download processed assets
uses: actions/download-artifact@v4
with:
name: phase-cli-release
path: ./phase-cli-release

- name: Attach assets to release
uses: softprops/action-gh-release@v2
with:
files: ./phase-cli-release/*
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
156 changes: 156 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
name: Build CLI

on:
workflow_call:
inputs:
version:
required: true
type: string
python_version:
required: true
type: string

jobs:
build:
name: Build CLI
runs-on: ${{ matrix.os }}
strategy:
matrix:
# ubuntu-20.04 - context: https://github.com/phasehq/cli/issues/94
# macos-13 darwin-amd64 builds (intel)
# macos-14 darwin-arm64 builds (apple silicon)
# context: https://github.com/actions/runner-images?tab=readme-ov-file#available-images

os: [ubuntu-20.04, windows-2022, macos-13, macos-14]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ inputs.python_version }}
- run: pip install -r requirements.txt
- run: pip install pyinstaller
- run: pyinstaller --hidden-import _cffi_backend --paths ./phase_cli --name phase phase_cli/main.py
- name: Print GLIBC version
if: matrix.os == 'ubuntu-20.04'
run: ldd --version

# Set LC_ALL based on the runner OS for Linux and macOS
- name: Set LC_ALL for Linux and macOS
run: export LC_ALL=C.UTF-8
if: runner.os != 'Windows'
shell: bash

# Set LC_ALL for Windows
- name: Set LC_ALL for Windows
run: echo "LC_ALL=C.UTF-8" | Out-File -Append -Encoding utf8 $env:GITHUB_ENV
if: runner.os == 'Windows'
shell: pwsh

# # Download the version file
# - uses: actions/download-artifact@v4
# with:
# name: phase-version

# # DEBUG
# - name: List files after downloading artifact
# shell: bash
# run: ls -al

# # Set the version environment variable
# - name: Set VERSION
# shell: bash
# run: |
# PHASE_CLI_VERSION=$(cat PHASE_CLI_VERSION.txt)
# echo "PHASE_CLI_VERSION is: $PHASE_CLI_VERSION"
# echo "PHASE_CLI_VERSION=$PHASE_CLI_VERSION" >> $GITHUB_ENV

# Build DEB and RPM packages for Linux
- run: |
sudo apt-get update
sudo apt-get install -y ruby-dev rubygems build-essential
sudo gem install --no-document fpm
fpm -s dir -t deb -n phase -v ${{ inputs.version }} dist/phase/=usr/bin/
fpm -s dir -t rpm -n phase -v ${{ inputs.version }} dist/phase/=usr/bin/
if: matrix.os == 'ubuntu-20.04'
shell: bash
# Upload DEB and RPM packages
- uses: actions/upload-artifact@v4
with:
name: phase-deb
path: "*.deb"
if: matrix.os == 'ubuntu-20.04'
- uses: actions/upload-artifact@v4
with:
name: phase-rpm
path: "*.rpm"
if: matrix.os == 'ubuntu-20.04'

- name: Set artifact name
run: |
if [[ "${{ matrix.os }}" == "macos-14" ]]; then
echo "ARTIFACT_NAME=${{ runner.os }}-arm64-binary" >> $GITHUB_ENV
elif [[ "${{ matrix.os }}" == "macos-13" ]]; then
echo "ARTIFACT_NAME=${{ runner.os }}-amd64-binary" >> $GITHUB_ENV
else
echo "ARTIFACT_NAME=${{ runner.os }}-binary" >> $GITHUB_ENV
fi
shell: bash

- name: Upload binary
uses: actions/upload-artifact@v4
with:
name: ${{ env.ARTIFACT_NAME }}
path: dist/phase*

build_arm:
name: Build Linux ARM64
runs-on: self-hosted
container:
image: python:3.11.0-bullseye
steps:
- uses: actions/checkout@v4
- name: Setup Environment
run: |
python --version
pip install -r requirements.txt
pip install pyinstaller
- name: Build with PyInstaller
run: pyinstaller --hidden-import _cffi_backend --paths ./phase_cli --name phase phase_cli/main.py
- uses: actions/upload-artifact@v4
with:
name: Linux-binary-arm64
path: dist/phase*

build_apk:
name: Build Alpine
runs-on: ubuntu-20.04
container:
image: python:3.11-alpine
steps:
- uses: actions/checkout@v4
- run: apk add --update --no-cache python3 python3-dev build-base
- run: python3 -m ensurepip
- run: pip3 install --no-cache --upgrade pip setuptools
- run: pip install -r requirements.txt
- run: pip install pyinstaller
- run: pyinstaller --hidden-import _cffi_backend --paths ./phase_cli --name phase phase_cli/main.py
- run: apk add alpine-sdk
- run: adduser -G abuild -g "Alpine Package Builder" -s /bin/ash -D builder
- run: mkdir /home/builder/package
- run: chown builder /home/builder/package
- run: apk add --no-cache sudo
- run: |
echo "builder ALL=(ALL) NOPASSWD: ALL" | sudo tee -a /etc/sudoers
ls ./dist/phase
cp -r ./dist/phase/* /home/builder/package/
cp ./APKBUILD /home/builder/package
cd /home/builder/package
sudo -u builder abuild-keygen -a -i -n
sudo -u builder abuild checksum
sudo -u builder abuild -r
shell: sh
- uses: actions/upload-artifact@v4
with:
name: phase-apk
path: /home/builder/packages/builder/x86_64/*.apk
Loading

0 comments on commit 255c231

Please sign in to comment.