Skip to content

Commit

Permalink
Merge pull request #12 from chkpwd/feat/restructure-workflow
Browse files Browse the repository at this point in the history
add initial restructure
  • Loading branch information
chkpwd committed Nov 15, 2024
2 parents 59ca632 + e67ceba commit 15ba191
Show file tree
Hide file tree
Showing 20 changed files with 1,155 additions and 419 deletions.
54 changes: 43 additions & 11 deletions .github/workflows/alfred.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,57 @@ on:
push:
tags:
- 'v*'
workflow_dispatch:

jobs:
build:
runs-on: ubuntu-latest

outputs:
OUTPUT_FILE: ${{ steps.builder.outputs.OUTPUT_FILE }}
steps:
- uses: actions/checkout@v4

- name: Build Alfred workflow
id: builder
run: |
cd ente-totp
python -m venv .venv
source .venv/bin/activate
./build.sh
env:
WORKFLOW_VERSION: ${{ github.ref_name }}

- name: Release
uses: softprops/action-gh-release@v1
python3 build.py
release:
needs: build
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4

- name: Parse tags
id: parse_tags
run: |
git fetch -a
echo "tag_count=$(git tag -l | wc -l)" >> $GITHUB_OUTPUT
- name: Update CHANGELOG
continue-on-error: ${{ steps.parse_tags.outputs.tag_count == '1' }}
id: changelog
uses: requarks/changelog-action@v1
with:
token: ${{ github.token }}
tag: ${{ github.ref_name }}

- name: Create Release
uses: ncipollo/release-action@v1
with:
allowUpdates: true
draft: false
makeLatest: true
name: ${{ github.ref_name }}
body: ${{ steps.changelog.outputs.changes }}
token: ${{ github.token }}
artifacts: ${{ needs.build.outputs.OUTPUT_FILE }}

- name: Commit CHANGELOG.md
uses: stefanzweifel/git-auto-commit-action@v5
with:
files: ${{ steps.builder.outputs.OUTPUT_FILE }}
branch: main
commit_message: 'docs: update CHANGELOG.md for ${{ github.ref_name }}'
file_pattern: CHANGELOG.md
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.DS_Store
__pycache__
*.alfredworkflow
*.zip
21 changes: 7 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
# An Alfred Workflow that uses your Ente Exports

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.

> [!NOTE]
> In the future, the workflow will take care of the import.
> In addtion, once support for exporting codes via CLI is supported, we will use that instead.
> [!WARNING]
> This workflow exports secrets from the Ente Auth CLI. Please exercise caution when using it.
## Setup

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

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

## Local Development

### Install dependencies
./build-deps.sh
### Install/Update dependencies
poetry install --only=main

### Build alfred workflow file
./build.sh

### Update requirements
pip install pip-tools
pip-compile requirements.in
python3 build.py
116 changes: 116 additions & 0 deletions build.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
#!/usr/bin/env python3

import os
import plistlib
import shutil
import subprocess
from zipfile import ZIP_STORED, ZipFile

import tomllib


def parse_info_plist():
"""Parse the info.plist file"""
with open("info.plist", "rb") as f:
plist = plistlib.load(f)
return plist


def get_workflow_name():
"""Get the workflow name from parsed plist"""
plist = parse_info_plist()
name = plist["name"].replace(" ", "_").lower()
return name


def get_workflow_version():
"""Get the workflow version from parsed plist"""
plist = parse_info_plist()
version = plist["version"].replace(" ", "_").lower()
return version


def get_pyproject_version():
"""Get the project version from pyproject.toml"""
with open("pyproject.toml", "rb") as f:
pyproject = tomllib.load(f)
version = pyproject["tool"]["poetry"]["version"]
return version


def update_version(version: str, plist_path: str = "info.plist"):
"""Update the version in info.plist"""
plist = parse_info_plist()
plist["version"] = version
with open(plist_path, "wb") as f:
plistlib.dump(plist, f)


def init_venv():
"""Initialize the venv"""

if os.path.exists(".venv"):
shutil.rmtree(".venv")

subprocess.run(["poetry", "install", "--only", "main"], check=True)

print("Dependencies installed successfully.")


def zip_workflow(filename: str):
"""Zip the workflow"""
basepath = os.getcwd()

zip_contents = [
"icon.png",
"info.plist",
"main.py",
"src",
".venv",
]
zip_contents = [os.path.join(basepath, file) for file in zip_contents]
zip_exlude = ["__pycache__"]

def should_include(path):
exclude_paths = any(excluded in path for excluded in zip_exlude)
include_paths = any(included in path for included in zip_contents)
return not exclude_paths and include_paths

with ZipFile(filename, "w", ZIP_STORED, strict_timestamps=False) as zip:
for root, _, files in os.walk(basepath):
for file in files:
full_path = os.path.join(root, file)
if should_include(full_path):
arcname = os.path.relpath(full_path, basepath)
zip.write(full_path, arcname)


def main():
workflow_name = get_workflow_name()
workflow_version = get_workflow_version()
pyproject_version = get_pyproject_version()

init_venv()

if workflow_version != pyproject_version:
update_version(pyproject_version)
else:
print("Workflow version matches PyProject version. Should this be updated?")

zip_name = f"{workflow_name}-{workflow_version}.alfredworkflow"
zip_workflow(zip_name)

if os.getenv("GITHUB_ACTIONS"):
with open(os.environ["GITHUB_OUTPUT"], "a") as f:
f.write(f"OUTPUT_FILE={zip_name}\n")

with open(os.environ["GITHUB_STEP_SUMMARY"], "a") as f:
f.write("# Alfred Workflow Build\n")
f.write(f"* Workflow name: {workflow_name}\n")
f.write(f"* Workflow version: {workflow_version}\n")
f.write(f"* Pyproject version: {pyproject_version}\n")
f.write(f"* ZIP name: {zip_name}\n")


if __name__ == "__main__":
main()
49 changes: 0 additions & 49 deletions build.sh

This file was deleted.

18 changes: 0 additions & 18 deletions build_deps.sh

This file was deleted.

40 changes: 0 additions & 40 deletions build_tools.py

This file was deleted.

Loading

0 comments on commit 15ba191

Please sign in to comment.