Skip to content

Commit

Permalink
Merge branch 'main' into jvasquezrojas-add-errors-to-telemetry
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-jvasquezrojas authored Jul 16, 2024
2 parents f1a9da4 + 8f638f4 commit 2e3a898
Show file tree
Hide file tree
Showing 7 changed files with 313 additions and 9 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/ok_to_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# If someone with write access comments "/ok-to-test" on a pull request, emit a repository_dispatch event
name: Ok To Test

on:
issue_comment:
types: [created]

jobs:
ok-to-test:
runs-on: ubuntu-latest
environment: ok-to-test
permissions:
pull-requests: write
# Only run for PRs, not issue comments
if: ${{ github.event.issue.pull_request }}
steps:
- uses: actions/create-github-app-token@v1
id: app-token
with:
app-id: ${{ secrets.APP_ID }}
private-key: ${{ secrets.PRIVATE_KEY }}

- name: Slash Command Dispatch
uses: peter-evans/slash-command-dispatch@13bc09769d122a64f75aa5037256f6f2d78be8c4
env:
TOKEN: ${{ steps.app-token.outputs.token }}
with:
token: ${{ env.TOKEN }}
reaction-token: ${{ secrets.GITHUB_TOKEN }}
issue-type: pull-request
commands: ok-to-test
permission: write
80 changes: 79 additions & 1 deletion .github/workflows/test_e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ on:
- "v*" # Push events to matching v*, i.e. v1.0, v20.15.10
branches:
- main
repository_dispatch:
types: [ok-to-test-command]
schedule:
- cron: "0 8 * * *"

Expand All @@ -19,14 +21,16 @@ concurrency:
jobs:
define-matrix:
uses: ./.github/workflows/matrix.yaml
tests:

e2e-trusted:
needs: define-matrix
strategy:
fail-fast: true
matrix:
os: ${{ fromJSON(needs.define-matrix.outputs.os) }}
python-version: ${{ fromJSON(needs.define-matrix.outputs.python) }}
runs-on: ${{ matrix.os }}
if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository
steps:
- uses: actions/checkout@v4
with:
Expand All @@ -47,3 +51,77 @@ jobs:
SNOWFLAKE_CONNECTIONS_INTEGRATION_PASSWORD: ${{ secrets.SNOWFLAKE_PASSWORD }}
SNOWFLAKE_CONNECTIONS_INTEGRATION_ACCOUNT: ${{ secrets.SNOWFLAKE_ACCOUNT }}
run: python -m hatch run e2e:test

# Repo owner has commented /ok-to-test on a (fork-based) pull request
e2e-fork:
needs: define-matrix
strategy:
fail-fast: true
matrix:
os: ${{ fromJSON(needs.define-matrix.outputs.os) }}
python-version: ${{ fromJSON(needs.define-matrix.outputs.python) }}
runs-on: ${{ matrix.os }}
permissions:
pull-requests: write
checks: write
if: |
github.event_name == 'repository_dispatch' &&
github.event.client_payload.slash_command.args.named.sha != '' &&
contains(
github.event.client_payload.pull_request.head.sha,
github.event.client_payload.slash_command.args.named.sha
)
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false
ref: 'refs/pull/${{ github.event.client_payload.pull_request.number }}/merge'
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip hatch
python -m hatch env create e2e
- name: Run end to end tests
env:
TERM: unknown
SNOWFLAKE_CONNECTIONS_INTEGRATION_HOST: ${{ secrets.SNOWFLAKE_HOST }}
SNOWFLAKE_CONNECTIONS_INTEGRATION_USER: ${{ secrets.SNOWFLAKE_USER }}
SNOWFLAKE_CONNECTIONS_INTEGRATION_PASSWORD: ${{ secrets.SNOWFLAKE_PASSWORD }}
SNOWFLAKE_CONNECTIONS_INTEGRATION_ACCOUNT: ${{ secrets.SNOWFLAKE_ACCOUNT }}
run: python -m hatch run e2e:test
# Update check run called "e2e-fork"
- uses: actions/github-script@v7
id: update-check-run
if: ${{ always() }}
env:
number: ${{ github.event.client_payload.pull_request.number }}
job: ${{ github.job }}
# Conveniently, job.status maps to https://developer.github.com/v3/checks/runs/#update-a-check-run
conclusion: ${{ job.status }}
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const { data: pull } = await github.rest.pulls.get({
...context.repo,
pull_number: process.env.number
});
const ref = pull.head.sha;
const { data: checks } = await github.rest.checks.listForRef({
...context.repo,
ref
});
const check = checks.check_runs.filter(c => c.name === process.env.job);
const { data: result } = await github.rest.checks.update({
...context.repo,
check_run_id: check[0].id,
status: 'completed',
conclusion: process.env.conclusion
});
return result;
81 changes: 80 additions & 1 deletion .github/workflows/test_integration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ on:
- "v*" # Push events to matching v*, i.e. v1.0, v20.15.10
branches:
- main
repository_dispatch:
types: [ok-to-test-command]
schedule:
- cron: "0 8 * * *"

Expand All @@ -20,14 +22,17 @@ concurrency:
jobs:
define-matrix:
uses: ./.github/workflows/matrix.yaml
tests:

# Branch-based pull request
integration-trusted:
needs: define-matrix
strategy:
fail-fast: true
matrix:
os: ${{ fromJSON(needs.define-matrix.outputs.os) }}
python-version: ${{ fromJSON(needs.define-matrix.outputs.python) }}
runs-on: ${{ matrix.os }}
if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository
steps:
- uses: actions/checkout@v4
with:
Expand All @@ -47,3 +52,77 @@ jobs:
SNOWFLAKE_CONNECTIONS_INTEGRATION_PASSWORD: ${{ secrets.SNOWFLAKE_PASSWORD }}
SNOWFLAKE_CONNECTIONS_INTEGRATION_ACCOUNT: ${{ secrets.SNOWFLAKE_ACCOUNT }}
run: python -m hatch run integration:test


# Repo owner has commented /ok-to-test on a (fork-based) pull request
integration-fork:
needs: define-matrix
strategy:
fail-fast: true
matrix:
os: ${{ fromJSON(needs.define-matrix.outputs.os) }}
python-version: ${{ fromJSON(needs.define-matrix.outputs.python) }}
runs-on: ${{ matrix.os }}
permissions:
pull-requests: write
checks: write
if: |
github.event_name == 'repository_dispatch' &&
github.event.client_payload.slash_command.args.named.sha != '' &&
contains(
github.event.client_payload.pull_request.head.sha,
github.event.client_payload.slash_command.args.named.sha
)
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false
ref: 'refs/pull/${{ github.event.client_payload.pull_request.number }}/merge'
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip hatch
python -m hatch env create integration
- name: Run integration tests
env:
TERM: unknown
SNOWFLAKE_CONNECTIONS_INTEGRATION_USER: ${{ secrets.SNOWFLAKE_USER }}
SNOWFLAKE_CONNECTIONS_INTEGRATION_PASSWORD: ${{ secrets.SNOWFLAKE_PASSWORD }}
SNOWFLAKE_CONNECTIONS_INTEGRATION_ACCOUNT: ${{ secrets.SNOWFLAKE_ACCOUNT }}
run: python -m hatch run integration:test
# Update check run called "integration-fork"
- uses: actions/github-script@v7
id: update-check-run
if: ${{ always() }}
env:
number: ${{ github.event.client_payload.pull_request.number }}
job: ${{ github.job }}
# Conveniently, job.status maps to https://developer.github.com/v3/checks/runs/#update-a-check-run
conclusion: ${{ job.status }}
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const { data: pull } = await github.rest.pulls.get({
...context.repo,
pull_number: process.env.number
});
const ref = pull.head.sha;
const { data: checks } = await github.rest.checks.listForRef({
...context.repo,
ref
});
const check = checks.check_runs.filter(c => c.name === process.env.job);
const { data: result } = await github.rest.checks.update({
...context.repo,
check_run_id: check[0].id,
status: 'completed',
conclusion: process.env.conclusion
});
return result;
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ dependencies = [
"rich==13.7.1",
"requests==2.32.3",
"requirements-parser==0.9.0",
"setuptools==70.2.0",
"setuptools==70.3.0",
'snowflake.core==0.8.0; python_version < "3.12"',
"snowflake-connector-python[secure-local-storage]==3.11.0",
'snowflake-snowpark-python>=1.15.0;python_version < "3.12"',
"tomlkit==0.12.5",
"tomlkit==0.13.0",
"typer==0.12.3",
"urllib3>=1.24.3,<2.3",
"GitPython==3.1.43",
Expand All @@ -57,7 +57,7 @@ classifiers = [

[project.optional-dependencies]
development = [
"coverage==7.5.4",
"coverage==7.6.0",
"pre-commit>=3.5.0",
"pytest==8.2.2",
"pytest-randomly==3.15.0",
Expand Down
6 changes: 3 additions & 3 deletions snyk/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ packaging
rich==13.7.1
requests==2.32.3
requirements-parser==0.9.0
setuptools==70.2.0
setuptools==70.3.0
snowflake.core==0.8.0; python_version < "3.12"
snowflake-connector-python[secure-local-storage]==3.11.0
snowflake-snowpark-python>=1.15.0;python_version < "3.12"
tomlkit==0.12.5
tomlkit==0.13.0
typer==0.12.3
urllib3>=1.24.3,<2.3
GitPython==3.1.43
pip
pydantic==2.8.2
coverage==7.5.4
coverage==7.6.0
pre-commit>=3.5.0
pytest==8.2.2
pytest-randomly==3.15.0
Expand Down
11 changes: 10 additions & 1 deletion src/snowflake/cli/plugins/init/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,22 @@ def _fetch_remote_template(
"""Downloads remote repository template to [dest],
and returns path to the template root.
Ends with an error of the template does not exist."""
from git import GitCommandError
from git import rmtree as git_rmtree

# TODO: during nativeapp refactor get rid of this dependency
from snowflake.cli.plugins.nativeapp.utils import shallow_git_clone

log.info("Downloading remote template from %s", url)
shallow_git_clone(url, to_path=destination.path)
try:
shallow_git_clone(url, to_path=destination.path)
except GitCommandError as err:
import re

if re.search("fatal: repository '.*' not found", err.stderr):
raise ClickException(f"Repository '{url}' does not exist")
raise

if path:
# template is a subdirectoruy of the repository
template_root = destination / path
Expand Down
Loading

0 comments on commit 2e3a898

Please sign in to comment.