Skip to content

feat: support prebuilt for MacOS M1 #119

feat: support prebuilt for MacOS M1

feat: support prebuilt for MacOS M1 #119

Workflow file for this run

name: Release
on:
push:
branches:
- main
workflow_dispatch:
concurrency:
group: ${{ github.ref }}-${{ github.workflow }}
cancel-in-progress: false
jobs:
prepare:
name: prepare
runs-on: ubuntu-latest
defaults:
run:
shell: bash
outputs:
CONTINUE: ${{ steps.set_continue.outputs.CONTINUE }}
LAST_COMMIT: ${{ steps.last-commit.outputs.message }}
PRE_RELEASE: ${{ steps.set_pre_release.outputs.PRE_RELEASE }}
VERSION: ${{ steps.get_version.outputs.VERSION }}
steps:
- name: Checkout repo
uses: actions/checkout@main
- name: Get Version
id: get_version
run: |
VERSION=$(grep VERSION "src/constants.py" | cut -d "=" -f 2 | sed 's/'\''//g' | sed 's/"//g' | sed 's/ //g' | sed 's/\r//')
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
- name: Set Continue
id: set_continue
run: |
REMOTE_VERSIONS=$(git ls-remote --tags -q | cut -d "/" -f 3)
for REMOTE_VERSION in ${REMOTE_VERSIONS[@]}; do
if [[ "${{ steps.get_version.outputs.VERSION }}" == "$REMOTE_VERSION" ]]; then
echo "Current version ${{ steps.get_version.outputs.VERSION }} is already released."
echo "CONTINUE=false" >>$GITHUB_OUTPUT
exit 0
fi
done
echo "CONTINUE=true" >>$GITHUB_OUTPUT
- name: Set Pre-Release
id: set_pre_release
run: |
VERSION_REGEX="^v[0-9]+\.[0-9]+\.[0-9]+$"
if [[ "${{ steps.get_version.outputs.VERSION }}" =~ $VERSION_REGEX ]]; then
echo "PRE_RELEASE=false" >> $GITHUB_OUTPUT
else
echo "PRE_RELEASE=true" >> $GITHUB_OUTPUT
fi
- name: Get last commit message
id: last-commit
run: echo "message=$(git log -1 --pretty=%s)" >> $GITHUB_OUTPUT
build:
name: build - ${{ matrix.os }}
needs: prepare
strategy:
fail-fast: false
matrix:
os:
- macos-13
- macos-latest
- ubuntu-latest
- windows-latest
runs-on: ${{ matrix.os }}
timeout-minutes: 10
if: ${{ needs.prepare.outputs.CONTINUE == 'true' }}
steps:
- name: get OS lowercase
id: get_os
shell: bash
run: |
case "${{ matrix.os }}" in
"macos-13") echo "OS_NAME_FOR_RELEASE=macos" >> "$GITHUB_ENV" ;;
"macos-latest") echo "OS_NAME_FOR_RELEASE=macos-m1" >> "$GITHUB_ENV" ;;
"ubuntu-latest") echo "OS_NAME_FOR_RELEASE=linux" >> "$GITHUB_ENV" ;;
"windows-latest") echo "OS_NAME_FOR_RELEASE=windows" >> "$GITHUB_ENV" ;;
esac
- name: Checkout repo
uses: actions/checkout@main
- name: Install python
uses: actions/setup-python@main
with:
cache: pip
python-version: "3.12"
- name: Install dependacies
run: pip install -r requirements/requirements.txt && pip install pyinstaller
- name: Build for ${{ env.OS_NAME_FOR_RELEASE }}
run: pyinstaller --noconfirm --onefile --console --icon="assets/images/VNU_HCM_LOGO-256.ico" --name="VNULIB-Downloader-${{ env.OS_NAME_FOR_RELEASE }}" --log-level="INFO" --add-data="src/:src/" --add-data="config-sample.yml:." --add-data="assets/images/error_page.jpg:assets/images/" --add-data="assets/utils/ascii_banner.txt:assets/utils/" --add-data="LICENSE:." --collect-data grapheme "main.py"
- name: Change permissions
if: runner.os == 'Linux' || runner.os == 'macOS'
run: chmod +x dist/VNULIB-Downloader-*
- name: Upload to artifact
uses: actions/upload-artifact@main
with:
name: VNULIB-Downloader-${{ env.OS_NAME_FOR_RELEASE }}
path: dist/VNULIB-Downloader-*
compression-level: 6
retention-days: 30
release:
name: Release
runs-on: ubuntu-latest
permissions:
contents: write
needs:
- prepare
- build
if: ${{ needs.prepare.outputs.CONTINUE == 'true' }}
steps:
- name: Download Artifact
uses: actions/download-artifact@main
- name: Upload to Release
uses: svenstaro/upload-release-action@master
with:
body: ${{ needs.prepare.outputs.LAST_COMMIT }}
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: ./VNULIB-Downloader-*/VNULIB-Downloader-*
release_name: VNULIB Downloader ${{ needs.prepare.outputs.VERSION }}
tag: ${{ needs.prepare.outputs.VERSION }}
file_glob: true
overwrite: false
prerelease: ${{ needs.prepare.outputs.PRE_RELEASE }}