Skip to content

Commit

Permalink
feat(gha): upload base theme
Browse files Browse the repository at this point in the history
WEB-4112
  • Loading branch information
remdub committed Jul 23, 2024
1 parent c4bb25d commit 2506d47
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 13 deletions.
18 changes: 5 additions & 13 deletions .github/workflows/build.yml → .github/workflows/build-upload.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ on:
workflow_dispatch:

jobs:
base-them:
base-theme:
runs-on:
group: self-hosted
steps:
Expand All @@ -27,16 +27,8 @@ jobs:
- name: Build theme
run: |
pnpm --theme=base build
- name: Install unzip
- name: Upload theme
run: |
sudo apt-get update && sudo apt-get install -y unzip
- name: Unzip theme
run: |
mkdir -p tmp/theme && unzip base/theme.zip -d tmp/theme
- name: Archive theme
uses: actions/[email protected]
with:
name: theme
path: |
tmp/theme
sudo apt-get update && sudo apt-get install -y python3-pip
pip3 install requests && pip install bs4
python3 theme_uploader.py ${{ vars.PLONE_URL }} ${{ secrets.PLONE_USER }} ${{ secrets.PLONE_PASSWORD }}
66 changes: 66 additions & 0 deletions theme_uploader.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
from bs4 import BeautifulSoup

import requests
import requests.cookies
import sys

INSTANCE_URL = sys.argv[1]
USERNAME = sys.argv[2]
PASSWORD = sys.argv[3]
THEME_LOCATION = "base/theme.zip"


def authenticate(
session: requests.Session, login_url: str, username: str, password: str
) -> requests.Response:
url = INSTANCE_URL + "/failsafe_login"
data = {
"__ac_name": USERNAME,
"__ac_password": PASSWORD,
"came_from": f"{INSTANCE_URL}/@@theming-controlpanel",
"buttons.login": "Se connecter",
}
response = session.post(url, data=data)
return response


def get_cookie(response: requests.Response) -> requests.cookies.RequestsCookieJar:
return response.cookies


def get_token(response: requests.Response) -> str:
soup = BeautifulSoup(response.text, "html.parser")
authenticator = soup.find(attrs={"name": "_authenticator"})
return authenticator["value"]


def upload_theme(
session: requests.Session,
instance_url: str,
token: str,
theme_location: str,
) -> requests.Response:
url = instance_url + "/@@theming-controlpanel"
with open(theme_location, "rb") as file_content:
file = {"themeArchive": ("theme.zip", file_content, "application/zip")}
data = {
"replaceExisting:boolean": "1",
"form.button.Import": "1",
"enableNewTheme:boolean": "1",
"_authenticator": token,
}
response = session.post(url, files=file, data=data)
return response


def main():
session = requests.Session()
response = authenticate(session, INSTANCE_URL, USERNAME, PASSWORD)
token = get_token(response)
response = upload_theme(session, INSTANCE_URL, token, THEME_LOCATION)
if response.status_code == 200:
print("Theme uploaded successfully")


if __name__ == "__main__":
main()

0 comments on commit 2506d47

Please sign in to comment.