ytdl-sub/.github/workflows/release.yaml
Jesse Bannon 592ca57d49 plz
2023-02-22 15:58:31 -08:00

173 lines
5.3 KiB
YAML

name: ytld-sub Release
on:
push:
# publish only when pushed to master
branches:
- master
pull_request:
jobs:
version:
name: version
runs-on: ubuntu-latest
outputs:
pypi_version: ${{ steps.set_outputs.outputs.pypi_version }}
local_version: ${{ steps.set_outputs.outputs.local_version }}
init_contents: ${{ steps.set_outputs.outputs.init_contents }}
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
ref: master # Needed for correct commit count. TODO: define once using GH actions
- name: Set version envs 1/3
run: |
echo "DATE=$(date +'%Y.%m.%d')" >> $GITHUB_ENV
echo "COMMIT_HASH=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
- name: Set version envs 2/3
run: |
echo "DATE_COMMIT_COUNT=$(git rev-list --count master --since='${{ env.DATE }} 00:00:00')" >> $GITHUB_ENV
- name: Set version envs 3/3
run: |
echo "LOCAL_VERSION=${{ env.DATE }}+${{ env.COMMIT_HASH }}" >> $GITHUB_ENV
if [ ${{ env.COMMIT_HASH }} = "0" ]
then
echo "PYPI_VERSION=${{ env.DATE }}" >> $GITHUB_ENV
else
echo "PYPI_VERSION=${{ env.DATE }}.post${{ env.DATE_COMMIT_COUNT }}" >> $GITHUB_ENV
fi
- name: Test versions
run: |
echo "${{ env.PYPI_VERSION }}"
echo "${{ env.LOCAL_VERSION }}"
- id: set_outputs
run: |
echo "pypi_version=${{ env.PYPI_VERSION }}" >> "$GITHUB_OUTPUT"
echo "local_version=${{ env.LOCAL_VERSION }}" >> "$GITHUB_OUTPUT"
echo 'init_contents=__pypi_version__ = "${{ env.PYPI_VERSION }}"\n__local_version__ = ${{ env.LOCAL_VERSION }}"' >> "$GITHUB_OUTPUT"
##################################################################################################
build-unix:
name: build-unix
needs:
- version
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Write version to init file
run: |
echo '${{ needs.version.outputs.init_contents }}' > src/ytdl_sub/__init__.py
- uses: actions/setup-python@v4
with:
python-version: '3.10'
- name: Install and Package
run: |
sudo apt-get -y install zip
pip install -e .[build]
EXEC_SUFFIX=_linux make executable
- name: Upload artifacts
uses: actions/upload-artifact@v3
with:
path: |
dist/ytdl-sub_linux
build-arm:
name: build-arm
needs:
- version
runs-on: ubuntu-latest
strategy:
matrix:
arch: [ "aarch64" ]
steps:
- uses: actions/checkout@v3
- name: Write version to init file
run: |
echo '${{ needs.version.outputs.init_contents }}' > src/ytdl_sub/__init__.py
- uses: uraimo/run-on-arch-action@v2
name: Run commands
id: runcmd
with:
arch: ${{ matrix.arch }}
distro: alpine_latest
# Mount the artifacts directory as /artifacts in the container
dockerRunArgs: |
--volume "${PWD}/artifacts:/artifacts"
# Set an output parameter `uname` for use in subsequent steps
run: |
apk add python3 py3-pip
python3 -m pip install -e .
echo "Done!"
python3 -m pip install pyinstaller
pyinstaller ytdl-sub.spec
mv dist/ytdl-sub /artifacts/ytdl-sub_${{ matrix.arch }}
- name: Upload artifacts
uses: actions/upload-artifact@v3
with:
path: |
artifacts/ytdl-sub_${{ matrix.arch }}
##################################################################################################
github-release:
name: github-release
needs:
- version
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Write version to init file
run: |
echo '${{ needs.version.outputs.init_contents }}' > src/ytdl_sub/__init__.py
- name: Create Release
if: ${{ github.ref == 'refs/heads/master' }}
id: create_release
uses: softprops/action-gh-release@v1
with:
name: ytdl-sub ${{ needs.version.outputs.pypi_version }}
tag_name: ${{ needs.version.outputs.pypi_version }}
body: |
See https://github.com/jmbannon/ytdl-sub#installation for installation steps
draft: false
prerelease: false
pypi-publish:
name: pypi-publish
needs:
- version
runs-on: ubuntu-22.04
strategy:
matrix:
python-version: [ "3.10" ]
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0 # Needed for correct commit count. TODO: define once using GH actions
ref: master
- name: Write version to init file
run: |
echo '${{ needs.version.outputs.init_contents }}' > src/ytdl_sub/__init__.py
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Build Wheel
run: |
make wheel
- name: Publish distribution 📦 to PyPI
if: ${{ github.ref == 'refs/heads/master' }}
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}