diff --git a/.github/workflows/host-test.yml b/.github/workflows/host-test.yml new file mode 100644 index 00000000..93e6ca67 --- /dev/null +++ b/.github/workflows/host-test.yml @@ -0,0 +1,60 @@ +name: Run tests + +on: + workflow_dispatch: + +jobs: + deploy: + runs-on: ubuntu-latest + if: github.event.pull_request != null + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-python@v3 + with: + python-version: 3.12 + - name: 'Setup Chrome and chromedriver' + uses: nanasess/setup-chromedriver@v2 + + - name: 'Setup chromedriver environment' + run: | + export DISPLAY=:99 + chromedriver --url-base=/wd/hub & + - name: Start XVFB + run: Xvfb :99 & + + - name: Setup uv + run: | + curl -LsSf https://astral.sh/uv/install.sh | sh + uv venv + + - name: Install package and Build + run: | + source .venv/bin/activate + uv pip install --upgrade pip + uv pip install wheel + uv pip install ".[dev]" + uv pip install PyGithub + npm ci + npm i + npm run build + npm run dist + timeout-minutes: 20 + + - name: Upload artifact + uses: actions/upload-artifact@v2 + with: + name: dist-artifact + path: dist/*.tar.gz + + - name: Get download URL + id: artifact + run: echo "artifact_url=https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}/artifacts" >> $GITHUB_ENV + + - name: Post Link + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GITHUB_REPOSITORY: ${{ github.repository }} + PR_NUMBER: ${{ github.event.pull_request.number }} + ARTIFACT_URL: ${{env.artifact_url}} + run: python deploy_test.py + diff --git a/PRs/requirements.txt b/PRs/requirements.txt index 9a22b9a2..7e03e4f6 100644 --- a/PRs/requirements.txt +++ b/PRs/requirements.txt @@ -1,2 +1 @@ -dash -dash_mantine_components \ No newline at end of file +dash \ No newline at end of file diff --git a/deploy_test.py b/deploy_test.py index 4e4e368c..0b0a136c 100644 --- a/deploy_test.py +++ b/deploy_test.py @@ -3,12 +3,14 @@ import base64 from urllib.parse import quote, urlencode import os +from github import Github files = [] code = '' +reqs = {} for f in os.listdir('PRs'): file_path = os.path.join('PRs', f) - if f != 'app.py': + if f not in ['app.py','requirements.txt']: with open(file_path, 'rb') as file: files.append( { @@ -17,9 +19,31 @@ "encoding": "base64" } ) - else: + elif f == 'app.py': with open(file_path, 'r') as file: code = file.read() + else: + with open(file_path, 'r') as file: + reqs = { + 'name': f, + 'content': file.read() + } + +# Find the last modified tar.gz file in the 'dist' directory +dist_path = 'dist' +latest_tar_gz = None +latest_time = 0 + +for f in os.listdir(dist_path): + if f.endswith('.tar.gz'): + file_path = os.path.join(dist_path, f) + modified_time = os.path.getmtime(file_path) + if modified_time > latest_time: + latest_time = modified_time + latest_tar_gz = file_path + +reqs['content'] += f'\n{os.environ.get("ARTIFACT_URL")}' +files.append(reqs) def generate_link(files, code): json_object = { @@ -35,4 +59,30 @@ def generate_link(files, code): type = "dash" # replace by dash, or streamlit return f"{base_url}/snippet/{type}/v1?{query}" -print(generate_link(files, code)) \ No newline at end of file +# Generate the link +link = generate_link(files, code) + +# Post the link as a comment on the pull request +def post_comment(link): + # Get environment variables + GITHUB_TOKEN = os.getenv('GITHUB_TOKEN') + REPO_NAME = os.getenv('GITHUB_REPOSITORY') + PR_NUMBER = int(os.getenv('PR_NUMBER')) + + # Initialize Github object + g = Github(GITHUB_TOKEN) + + # Get the repository + repo = g.get_repo(REPO_NAME) + + # Get the pull request + pull_request = repo.get_pull(PR_NUMBER) + + # Add a comment to the pull request + comment_body = f"Generated link: {link}" + pull_request.create_issue_comment(comment_body) + + print("Comment added to the pull request.") + +# Call the function to post the comment +post_comment(link) \ No newline at end of file diff --git a/package.json b/package.json index 9316adc0..72fac8a1 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,8 @@ "build:js": "webpack", "build:backends": "dash-generate-components ./src/ts/components dash_mantine_components -p package-info.json --r-prefix '' --jl-prefix '' --ignore \\.test\\.", "build": "npm run build:js && npm run build:backends", - "watch": "npm run build:js::dev -- --watch" + "watch": "npm run build:js::dev -- --watch", + "dist": "python setup.py sdist bdist_wheel" }, "devDependencies": { "@braintree/sanitize-url": "^7.0.0",