Skip to content

Commit 15ba191

Browse files
committed
Merge pull request #12 from chkpwd/feat/restructure-workflow
add initial restructure
2 parents 59ca632 + e67ceba commit 15ba191

20 files changed

+1155
-419
lines changed

.github/workflows/alfred.yml

+43-11
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,57 @@ on:
44
push:
55
tags:
66
- 'v*'
7+
workflow_dispatch:
78

89
jobs:
910
build:
1011
runs-on: ubuntu-latest
11-
12+
outputs:
13+
OUTPUT_FILE: ${{ steps.builder.outputs.OUTPUT_FILE }}
1214
steps:
1315
- uses: actions/checkout@v4
1416

1517
- name: Build Alfred workflow
1618
id: builder
1719
run: |
18-
cd ente-totp
19-
python -m venv .venv
20-
source .venv/bin/activate
21-
./build.sh
22-
env:
23-
WORKFLOW_VERSION: ${{ github.ref_name }}
24-
25-
- name: Release
26-
uses: softprops/action-gh-release@v1
20+
python3 build.py
21+
22+
release:
23+
needs: build
24+
runs-on: ubuntu-latest
25+
permissions:
26+
contents: write
27+
steps:
28+
- uses: actions/checkout@v4
29+
30+
- name: Parse tags
31+
id: parse_tags
32+
run: |
33+
git fetch -a
34+
echo "tag_count=$(git tag -l | wc -l)" >> $GITHUB_OUTPUT
35+
36+
- name: Update CHANGELOG
37+
continue-on-error: ${{ steps.parse_tags.outputs.tag_count == '1' }}
38+
id: changelog
39+
uses: requarks/changelog-action@v1
40+
with:
41+
token: ${{ github.token }}
42+
tag: ${{ github.ref_name }}
43+
44+
- name: Create Release
45+
uses: ncipollo/release-action@v1
46+
with:
47+
allowUpdates: true
48+
draft: false
49+
makeLatest: true
50+
name: ${{ github.ref_name }}
51+
body: ${{ steps.changelog.outputs.changes }}
52+
token: ${{ github.token }}
53+
artifacts: ${{ needs.build.outputs.OUTPUT_FILE }}
54+
55+
- name: Commit CHANGELOG.md
56+
uses: stefanzweifel/git-auto-commit-action@v5
2757
with:
28-
files: ${{ steps.builder.outputs.OUTPUT_FILE }}
58+
branch: main
59+
commit_message: 'docs: update CHANGELOG.md for ${{ github.ref_name }}'
60+
file_pattern: CHANGELOG.md

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.DS_Store
2+
__pycache__
3+
*.alfredworkflow
4+
*.zip

README.md

+7-14
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
# An Alfred Workflow that uses your Ente Exports
22

3-
The Ente Auth CLI does not support exporting TOTP codes. To use this project, please export TOTP codes from the Ente app and then import them into the workflow's database by selecting the export file using the "Configure Workflow" button in the workflow setup. You can import the file using the `ente import` Alfred command. Once imported, you can delete the file.
4-
5-
> [!NOTE]
6-
> In the future, the workflow will take care of the import.
7-
> In addtion, once support for exporting codes via CLI is supported, we will use that instead.
3+
> [!WARNING]
4+
> This workflow exports secrets from the Ente Auth CLI. Please exercise caution when using it.
85
96
## Setup
107

@@ -15,18 +12,14 @@ The Ente Auth CLI does not support exporting TOTP codes. To use this project, pl
1512

1613
1. Open Alfred
1714
2. Go to Workflows.
18-
3. Click the "Enter 2FA" workflow and click the Configure Workflow button.
19-
4. Next, click the file button next to "Ente Export File" and browse to your Ente Auth plain text export of two-factor codes.
15+
3. Click the "Ente Auth" workflow and click the Configure Workflow button.
16+
4. Next, configure the settings (NOTE: the export path is what you configured when adding your ente account).
2017
5. Finally, run the Alfred command `ente import`.
2118

2219
## Local Development
2320

24-
### Install dependencies
25-
./build-deps.sh
21+
### Install/Update dependencies
22+
poetry install --only=main
2623

2724
### Build alfred workflow file
28-
./build.sh
29-
30-
### Update requirements
31-
pip install pip-tools
32-
pip-compile requirements.in
25+
python3 build.py

build.py

+116
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
#!/usr/bin/env python3
2+
3+
import os
4+
import plistlib
5+
import shutil
6+
import subprocess
7+
from zipfile import ZIP_STORED, ZipFile
8+
9+
import tomllib
10+
11+
12+
def parse_info_plist():
13+
"""Parse the info.plist file"""
14+
with open("info.plist", "rb") as f:
15+
plist = plistlib.load(f)
16+
return plist
17+
18+
19+
def get_workflow_name():
20+
"""Get the workflow name from parsed plist"""
21+
plist = parse_info_plist()
22+
name = plist["name"].replace(" ", "_").lower()
23+
return name
24+
25+
26+
def get_workflow_version():
27+
"""Get the workflow version from parsed plist"""
28+
plist = parse_info_plist()
29+
version = plist["version"].replace(" ", "_").lower()
30+
return version
31+
32+
33+
def get_pyproject_version():
34+
"""Get the project version from pyproject.toml"""
35+
with open("pyproject.toml", "rb") as f:
36+
pyproject = tomllib.load(f)
37+
version = pyproject["tool"]["poetry"]["version"]
38+
return version
39+
40+
41+
def update_version(version: str, plist_path: str = "info.plist"):
42+
"""Update the version in info.plist"""
43+
plist = parse_info_plist()
44+
plist["version"] = version
45+
with open(plist_path, "wb") as f:
46+
plistlib.dump(plist, f)
47+
48+
49+
def init_venv():
50+
"""Initialize the venv"""
51+
52+
if os.path.exists(".venv"):
53+
shutil.rmtree(".venv")
54+
55+
subprocess.run(["poetry", "install", "--only", "main"], check=True)
56+
57+
print("Dependencies installed successfully.")
58+
59+
60+
def zip_workflow(filename: str):
61+
"""Zip the workflow"""
62+
basepath = os.getcwd()
63+
64+
zip_contents = [
65+
"icon.png",
66+
"info.plist",
67+
"main.py",
68+
"src",
69+
".venv",
70+
]
71+
zip_contents = [os.path.join(basepath, file) for file in zip_contents]
72+
zip_exlude = ["__pycache__"]
73+
74+
def should_include(path):
75+
exclude_paths = any(excluded in path for excluded in zip_exlude)
76+
include_paths = any(included in path for included in zip_contents)
77+
return not exclude_paths and include_paths
78+
79+
with ZipFile(filename, "w", ZIP_STORED, strict_timestamps=False) as zip:
80+
for root, _, files in os.walk(basepath):
81+
for file in files:
82+
full_path = os.path.join(root, file)
83+
if should_include(full_path):
84+
arcname = os.path.relpath(full_path, basepath)
85+
zip.write(full_path, arcname)
86+
87+
88+
def main():
89+
workflow_name = get_workflow_name()
90+
workflow_version = get_workflow_version()
91+
pyproject_version = get_pyproject_version()
92+
93+
init_venv()
94+
95+
if workflow_version != pyproject_version:
96+
update_version(pyproject_version)
97+
else:
98+
print("Workflow version matches PyProject version. Should this be updated?")
99+
100+
zip_name = f"{workflow_name}-{workflow_version}.alfredworkflow"
101+
zip_workflow(zip_name)
102+
103+
if os.getenv("GITHUB_ACTIONS"):
104+
with open(os.environ["GITHUB_OUTPUT"], "a") as f:
105+
f.write(f"OUTPUT_FILE={zip_name}\n")
106+
107+
with open(os.environ["GITHUB_STEP_SUMMARY"], "a") as f:
108+
f.write("# Alfred Workflow Build\n")
109+
f.write(f"* Workflow name: {workflow_name}\n")
110+
f.write(f"* Workflow version: {workflow_version}\n")
111+
f.write(f"* Pyproject version: {pyproject_version}\n")
112+
f.write(f"* ZIP name: {zip_name}\n")
113+
114+
115+
if __name__ == "__main__":
116+
main()

build.sh

-49
This file was deleted.

build_deps.sh

-18
This file was deleted.

build_tools.py

-40
This file was deleted.

0 commit comments

Comments
 (0)