From cf8440c9cecd360fcad901391279628ae52249a3 Mon Sep 17 00:00:00 2001 From: Hoang Dinh Date: Mon, 26 Feb 2024 11:28:48 +0700 Subject: [PATCH] chore: refactor build binaries workflow - Move the content of the build binaries action into build binaries workflow. Doing this so that we can easily add more parameters to platform specified build binaries actions. - Rename some steps in the CD workflow --- .github/actions/build-binaries/action.yaml | 90 ---------------------- .github/workflows/build-binaries.yaml | 87 +++++++++++++++++++-- .github/workflows/cd.yaml | 4 +- .github/workflows/pr.yaml | 1 + 4 files changed, 85 insertions(+), 97 deletions(-) delete mode 100644 .github/actions/build-binaries/action.yaml diff --git a/.github/actions/build-binaries/action.yaml b/.github/actions/build-binaries/action.yaml deleted file mode 100644 index 35e05b2f..00000000 --- a/.github/actions/build-binaries/action.yaml +++ /dev/null @@ -1,90 +0,0 @@ -name: "Setup, Build, and Test Pyinstaller Binaries" -description: "Build, test and upload binaries to GitHub releases and/or artifacts (ensure poetry dependencies are installed before running this action)" -inputs: - production_release: - description: "Flag to determine if this is a production release" - required: true - operating_system: - description: "Operating system to set the correct binary path and extension" - required: true - architecture: - description: "Architecture to set the correct binary path and extension" - required: true - -runs: - using: "composite" - steps: - - name: Set release version - shell: bash - continue-on-error: true - if: ${{ inputs.production_release == 'true' }} - run: | - echo "RELEASE_VERSION_TAG=$(git describe --tags $(git rev-list --tags --max-count=1))" >> $GITHUB_ENV - - - name: Configure build environment - shell: bash - run: | - artifacts_dir="${{ github.workspace }}${{ inputs.operating_system == 'Windows' && '\dist\artifacts' || '/dist/artifacts' }}" - mkdir -p $artifacts_dir - if [ -n "${RELEASE_VERSION_TAG}" ]; then - release_version="${RELEASE_VERSION_TAG:1}" - package_name_version="-${release_version}" - echo "RELEASE_VERSION=${release_version}" >> $GITHUB_ENV - fi - package_name="algokit${package_name_version}-${{ inputs.operating_system }}_${{ inputs.architecture }}" - echo "PACKAGE_NAME=`echo $package_name | tr '[:upper:]' '[:lower:]'`" >> $GITHUB_ENV - echo "ARTIFACTS_DIR=${artifacts_dir}" >> $GITHUB_ENV - - # GitHub doesn't support expressions in the uses block - - name: Build windows binary - if: ${{ inputs.operating_system == 'Windows' }} - uses: ./.github/actions/build-binaries/windows - with: - package_name: ${{ env.PACKAGE_NAME }} - version: ${{ env.RELEASE_VERSION }} - artifacts_dir: ${{ env.ARTIFACTS_DIR }} - - - name: Build linux binary - if: ${{ inputs.operating_system == 'Linux' }} - uses: ./.github/actions/build-binaries/linux - with: - package_name: ${{ env.PACKAGE_NAME }} - version: ${{ env.RELEASE_VERSION }} - artifacts_dir: ${{ env.ARTIFACTS_DIR }} - - - name: Build macOS binary - if: ${{ inputs.operating_system == 'macOS' }} - uses: ./.github/actions/build-binaries/macos - with: - package_name: ${{ env.PACKAGE_NAME }} - version: ${{ env.RELEASE_VERSION }} - artifacts_dir: ${{ env.ARTIFACTS_DIR }} - - - name: Add binary to path - run: | - echo "${{ github.workspace }}${{ inputs.operating_system == 'Windows' && '\dist\algokit' || '/dist/algokit' }}" >> $GITHUB_PATH - shell: bash - - - name: Run portability tests - run: | - git config --global user.email "actions@github.com" && git config --global user.name "github-actions" - poetry run pytest tests/ -m pyinstaller_binary_tests --log-cli-level=INFO - shell: ${{ inputs.operating_system == 'Windows' && 'cmd' || 'bash' }} - - # softprops/action-gh-release doesn't support the \ character in paths - - name: Adjust artifacts directory for softprops/action-gh-release - if: ${{ inputs.operating_system == 'Windows' }} - shell: pwsh - run: | - $adjusted = '${{ env.ARTIFACTS_DIR }}' -replace '\\','/' - echo "ARTIFACTS_DIR=$adjusted" >> $env:GITHUB_ENV - - - name: Append artifacts to release - if: ${{ inputs.production_release == 'true' }} - uses: softprops/action-gh-release@v1 - with: - fail_on_unmatched_files: true - files: | - ${{ env.ARTIFACTS_DIR }}/*.* - tag_name: ${{ env.RELEASE_VERSION_TAG }} - prerelease: ${{ contains(env.RELEASE_VERSION_TAG, 'beta') }} diff --git a/.github/workflows/build-binaries.yaml b/.github/workflows/build-binaries.yaml index ad208b60..230f2f70 100644 --- a/.github/workflows/build-binaries.yaml +++ b/.github/workflows/build-binaries.yaml @@ -17,6 +17,7 @@ jobs: matrix: # macos-14 is the Apple Silicon M1 runner os: [ubuntu-20.04, windows-latest, macos-latest, macos-14] + steps: - name: Checkout source code uses: actions/checkout@v4 @@ -34,9 +35,85 @@ jobs: - name: Install dependencies run: poetry install --no-interaction - - name: Build & test binary - uses: ./.github/actions/build-binaries + - name: Set release version + shell: bash + continue-on-error: true + if: ${{ inputs.production_release == 'true' }} + run: | + echo "RELEASE_VERSION_TAG=$(git describe --tags $(git rev-list --tags --max-count=1))" >> $GITHUB_ENV + + - name: Configure build environment + shell: bash + run: | + artifacts_dir="${{ github.workspace }}${{ runner.os == 'Windows' && '\dist\artifacts' || '/dist/artifacts' }}" + mkdir -p $artifacts_dir + if [ -n "${RELEASE_VERSION_TAG}" ]; then + release_version="${RELEASE_VERSION_TAG:1}" + package_name_version="-${release_version}" + echo "RELEASE_VERSION=${release_version}" >> $GITHUB_ENV + fi + package_name="algokit${package_name_version}-${{ runner.os }}_${{ runner.arch }}" + echo "PACKAGE_NAME=`echo $package_name | tr '[:upper:]' '[:lower:]'`" >> $GITHUB_ENV + echo "ARTIFACTS_DIR=${artifacts_dir}" >> $GITHUB_ENV + + # GitHub doesn't support expressions in the uses block + - name: Build windows binary + if: ${{ runner.os == 'Windows' }} + uses: ./.github/actions/build-binaries/windows + with: + package_name: ${{ env.PACKAGE_NAME }} + version: ${{ env.RELEASE_VERSION }} + artifacts_dir: ${{ env.ARTIFACTS_DIR }} + + - name: Build linux binary + if: ${{ runner.os == 'Linux' }} + uses: ./.github/actions/build-binaries/linux + with: + package_name: ${{ env.PACKAGE_NAME }} + version: ${{ env.RELEASE_VERSION }} + artifacts_dir: ${{ env.ARTIFACTS_DIR }} + + - name: Build macOS binary + if: ${{ runner.os == 'macOS' }} + uses: ./.github/actions/build-binaries/macos + with: + package_name: ${{ env.PACKAGE_NAME }} + version: ${{ env.RELEASE_VERSION }} + artifacts_dir: ${{ env.ARTIFACTS_DIR }} + + - name: Add binary to path + run: | + echo "${{ github.workspace }}${{ runner.os == 'Windows' && '\dist\algokit' || '/dist/algokit' }}" >> $GITHUB_PATH + shell: bash + + - name: Run portability tests + if: ${{ runner.os == 'Windows' }} + run: | + git config --global user.email "actions@github.com" && git config --global user.name "github-actions" + poetry run pytest tests/ -m pyinstaller_binary_tests --log-cli-level=INFO + shell: cmd + + - name: Run portability tests + if: ${{ runner.os != 'Windows' }} + run: | + git config --global user.email "actions@github.com" && git config --global user.name "github-actions" + poetry run pytest tests/ -m pyinstaller_binary_tests --log-cli-level=INFO + shell: bash + + # softprops/action-gh-release doesn't support the \ character in paths + - name: Adjust artifacts directory for softprops/action-gh-release + if: ${{ runner.os == 'Windows' }} + shell: pwsh + run: | + $adjusted = '${{ env.ARTIFACTS_DIR }}' -replace '\\','/' + echo "ARTIFACTS_DIR=$adjusted" >> $env:GITHUB_ENV + + - name: Append artifacts to release + if: ${{ inputs.production_release == 'true' }} + uses: softprops/action-gh-release@v1 with: - production_release: ${{ inputs.production_release }} - operating_system: ${{ runner.os }} - architecture: ${{ runner.arch }} + fail_on_unmatched_files: true + files: | + ${{ env.ARTIFACTS_DIR }}/*.* + tag_name: ${{ env.RELEASE_VERSION_TAG }} + prerelease: ${{ contains(env.RELEASE_VERSION_TAG, 'beta') }} diff --git a/.github/workflows/cd.yaml b/.github/workflows/cd.yaml index 48f05b5b..5217dce4 100644 --- a/.github/workflows/cd.yaml +++ b/.github/workflows/cd.yaml @@ -111,7 +111,7 @@ jobs: path: dist/algokit*-py3-none-any.whl if-no-files-found: error - upload-binaries: + build-and-upload-binaries: name: Build and Upload Binaries if: ${{ github.ref_name == 'main' }} uses: ./.github/workflows/build-binaries.yaml @@ -123,7 +123,7 @@ jobs: cd-publish-release-packages: name: Publish Release Packages - needs: upload-binaries + needs: build-and-upload-binaries if: ${{ github.ref_name == 'main' && inputs.production_release == 'true' }} # Might want to adjust this to publish (pre-release) on merge as well. uses: ./.github/workflows/publish-release-packages.yaml with: diff --git a/.github/workflows/pr.yaml b/.github/workflows/pr.yaml index 7c002623..602b7093 100644 --- a/.github/workflows/pr.yaml +++ b/.github/workflows/pr.yaml @@ -23,3 +23,4 @@ jobs: with: production_release: "false" python_version: "3.12" + secrets: inherit