Skip to content

Commit

Permalink
ci: releasing lightning nighties (#19661)
Browse files Browse the repository at this point in the history
* adding workflow
* convert_version2nightly
* allow-local-changes
  • Loading branch information
Borda committed Mar 17, 2024
1 parent dd6d689 commit 3b74d37
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 2 deletions.
15 changes: 15 additions & 0 deletions .actions/assistant.py
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,21 @@ def _copy_rst(rst_in, rst_out, as_orphan: bool = False):
with open(rst_out, "w", encoding="utf-8") as fopen:
fopen.write(page)

@staticmethod
def convert_version2nightly(ver_file: str = "src/version.info") -> None:
"""Load the actual version and convert it to the nightly version."""
from datetime import datetime

with open(ver_file) as fo:
version = fo.read().strip()
# parse X.Y.Z version and prune any suffix
vers = re.match(r"(\d+)\.(\d+)\.(\d+).*", version)
# create timestamp YYYYMMDD
timestamp = datetime.now().strftime("%Y%m%d")
version = f"{'.'.join(vers.groups())}.dev{timestamp}"
with open(ver_file, "w") as fo:
fo.write(version + os.linesep)


if __name__ == "__main__":
import jsonargparse
Expand Down
10 changes: 9 additions & 1 deletion .github/actions/pkg-check/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ inputs:
description: nb of packages in the wrap/distribution
required: false
default: "1"
allow-local-changes:
description: allow changes in the local git repo
required: false
default: "false"

runs:
using: "composite"
Expand All @@ -30,9 +34,13 @@ runs:
run: python setup.py sdist bdist_wheel
shell: bash

- name: Make sure there are no local unstated changes
if: ${{ inputs.allow-local-changes != 'true' }}
run: git diff --exit-code || exit $?
shell: bash

- name: Check package
run: |
git diff --exit-code || exit $? # make sure there are no local unstaged changes
ls -l dist/
twine check dist/*
shell: bash
Expand Down
78 changes: 78 additions & 0 deletions .github/workflows/release-nightly.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
name: Nightly packages

on:
pull_request: # this shall test only the part of workflow before publishing
branches: [master, "release/*"]
types: [opened, reopened, ready_for_review, synchronize]
paths:
- "requirements/ci.txt"
- ".github/actions/pkg-check/*"
- ".github/actions/pkg-publish/*"
- ".github/workflows/release-nightly.yml"
schedule:
- cron: "0 0 * * 0" # on Sundays
workflow_dispatch: {}

defaults:
run:
shell: bash

env:
FREEZE_REQUIREMENTS: 1
TORCH_URL: "https://download.pytorch.org/whl/cpu/torch_stable.html"
PYTHON_VER: "3.8"

jobs:
build-packages:
runs-on: ubuntu-22.04
env:
PKG_NAME: "lightning"
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: 3.9

- name: Convert actual version to nightly
run: |
pip install -q -r .actions/requirements.txt
python .actions/assistant.py convert_version2nightly
- run: python -c "print('NB_DIRS=' + str(2 if '${{ env.PKG_NAME }}' == 'pytorch' else 1))" >> $GITHUB_ENV
- name: Build & check package
uses: ./.github/actions/pkg-check
with:
pkg-name: ${{ env.PKG_NAME }}
nb-dirs: ${{ env.NB_DIRS }}
allow-local-changes: "true"

- uses: actions/upload-artifact@v4
with:
name: nightly-packages-${{ github.sha }}
path: dist

publish-packages:
runs-on: ubuntu-22.04
needs: build-packages
if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch'
env:
PKG_NAME: "lightning"
steps:
- uses: actions/checkout@v4 # needed for local action below
- uses: actions/download-artifact@v4
with:
name: nightly-packages-${{ github.sha }}
path: dist
- name: Browse folder
id: folder
run: |
sudo apt install -q -y tree
tree -L 2 -h dist/
python -c "print('pkg=' + '${{ env.PKG_NAME }}'.lower())" >> $GITHUB_OUTPUT
- uses: ./.github/actions/pkg-publish
with:
pkg-folder: dist/${{ steps.folder.outputs.pkg }}
pypi-test-token: ${{ secrets[format('PYPI_TEST_TOKEN_{0}', env.PKG_NAME)] }}
- uses: ./.github/actions/pkg-publish
with:
pkg-folder: dist/${{ steps.folder.outputs.pkg }}
pypi-token: ${{ secrets[format('PYPI_TOKEN_{0}', env.PKG_NAME)] }}
3 changes: 2 additions & 1 deletion .github/workflows/release-pkg.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Releasing package
name: Releasing packages

# https://help.github.com/en/actions/reference/events-that-trigger-workflows
on:
Expand All @@ -11,6 +11,7 @@ on:
types: [opened, reopened, ready_for_review, synchronize]
paths:
- "requirements/ci.txt"
- ".github/actions/pkg-check/*"
- ".github/actions/pkg-publish/*"
- ".github/workflows/_legacy-checkpoints.yml.yml"
- ".github/workflows/_build-packages.yml"
Expand Down

0 comments on commit 3b74d37

Please sign in to comment.