我正在尝试从 Github 工作流向 PyPI 发布 Python package,但“Test PyPI”的身份验证失败。我从命令行成功发布到 Test PyPI,所以我的 API 令牌必须是正确的。我还检查了秘密值中的前导和尾随空格(即在 GitHub 上)。
如上次提交所示,我尝试了一些事情但没有成功。
我首先尝试将简单的 bash 命令内联到工作流程中,如下所示,但我无法将我的秘密放入环境变量中。当我打印这些变量时,日志中没有显示任何内容。
from selenium import webdriver
import time
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
PATH = "C:\Program Files (x86)\chromedriver.exe"
driver = webdriver.Chrome(PATH)
driver.get("https://www.canva.com/en_gb/login/")
#fullscreen
driver.set_window_size(1024, 600)
driver.maximize_window()
#login
button = driver.find_element_by_xpath("/html/body/div[3]/div/main/div[6]/div/section/div/div/div/div/div/div/div[4]/form/div[1]/div/div/div/input")
button.send_keys("xegepor496@566dh.com")
#password
button = driver.find_element_by_xpath("/html/body/div[3]/div/main/div[6]/div/section/div/div/div/div/div/div/div[4]/form/div[2]/input")
button.send_keys("test12345test")
#log in
button = driver.find_element_by_xpath("/html/body/div[3]/div/main/div[6]/div/section/div/div/div/div/div/div/div[4]/form/button")
button.click()
#create project
wait = WebDriverWait(driver, 70)
button = wait.until(EC.element_to_be_clickable(
(By.XPATH, "/html/body/div[2]/div/div/div/header/div/header/div[5]/div/button")))
button.click()
#custom size
wait = WebDriverWait(driver, 70)
button = wait.until(EC.element_to_be_clickable(
(By.XPATH, "/html/body/div[1]/div/div/div/div/div/div[3]/div[1]/button")))
button.click()
#dimensions click
wait = WebDriverWait(driver, 70)
button = wait.until(EC.element_to_be_clickable(
(By.XPATH, "/html/body/div[1]/div/div/div/div/div/div[2]/form/div[1]/div/div[3]/div/button")))
button.click()
#choose dimensions in inches
wait = WebDriverWait(driver, 70)
button = wait.until(EC.element_to_be_clickable(
(By.XPATH, "/html/body/div[1]/div[1]/div/div[2]/div/div/ul/li[2]/button")))
button.click()
time.sleep(3)
#width
wait = WebDriverWait(driver, 70)
button = wait.until(EC.element_to_be_clickable((By.XPATH,
"/html/body/div[1]/div/div/div/div/div/div[2]/form/div[1]/div/div[1]/input")))
button.send_keys("17")
time.sleep(1)
#height
wait = WebDriverWait(driver, 70)
button = wait.until(EC.element_to_be_clickable((By.XPATH,
"/html/body/div[1]/div/div/div/div/div/div[2]/form/div[1]/div/div[2]/input")))
button.send_keys("11")
#create new project
wait = WebDriverWait(driver, 70)
button = wait.until(EC.element_to_be_clickable(
(By.XPATH, "/html/body/div[1]/div/div/div/div/div/div[2]/form/div[2]/button")))
button.click()
time.sleep(3)
#uploaded
button = driver.find_elements_by_xpath("/html/body/div[2]/div/div/div/div[3]/div/div/aside/div[1]/div[1]/div[1]/aside/div[3]/div/div[1]/div/div/div[2]/div[2]/div/button").click()
我也尝试使用专用的 GitHub Action 如下,但它也不起作用。我想问题出在我的工作流程中不可用的秘密。让我感到困惑的是 my workflow 使用另一个令牌/秘密就好了!但是,如果我将它放在环境变量中,则不会打印任何内容。我还以不同的名称(PYPI_TEST_TOKEN 和 TEST_PYPI_API_TOKEN)重新创建了我的秘密,但无济于事。
button = driver.find_elements_by_xpath("/html/body/div[2]/div/div/div/div[3]/div/div/aside/div[1]/div[1]/div[1]/aside/div[3]/div/div[1]/div/div/div[2]/div[2]/div/button").click()
AttributeError: 'list' object has no attribute 'click'
我想我错过了一些明显的东西(像往常一样)。非常感谢任何帮助。
答案 0 :(得分:4)
我终于明白了。我的错误是我在一个环境中定义了我的秘密,默认情况下,工作流不在任何特定环境中运行。为此,我必须在工作描述中明确命名环境如下:
jobs:
publish:
environment: CI # <--- /!\ Here is the link to the environment
needs: build
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/v')
steps:
- uses: actions/checkout@v2
# Some more steps here ...
- name: Publish to Test PyPI
env:
TWINE_USERNAME: "__token__"
TWINE_PASSWORD: ${{ secrets.TEST_PYPI_API_TOKEN }}
TWINE_REPOSITORY_URL: "https://test.pypi.org/legacy/"
run: |
echo KEY: '${TWINE_PASSWORD}'
twine check dist/*
twine upload --verbose --skip-existing dist/*
documentation 实际上提到了它。
感谢那些给我指出正确方向的评论。