Skip to content

Commit

Permalink
Automate logo generation
Browse files Browse the repository at this point in the history
  • Loading branch information
jngrad committed Jun 17, 2024
1 parent 25e9cde commit c54f7d9
Show file tree
Hide file tree
Showing 4 changed files with 161 additions and 8 deletions.
51 changes: 51 additions & 0 deletions .github/workflows/logos.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: logos

on:
push:
pull_request:

permissions:
contents: read # to fetch code (actions/checkout)

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@main
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y --no-install-recommends inkscape fonts-dejavu make sed
- name: Create logos
run: |
make all
mkdir -p github_artifacts
mv $(make list) ./github_artifacts/
echo -e "# pyMBE logos\n\nOfficial pyMBE logos and banners.\n\nThese files are automatically regenerated after each push to branch \`corporate-design\`." > ./github_artifacts/Readme.md
shell: bash
- name: Upload logos as artifact
uses: actions/upload-artifact@v4
with:
name: logo_files
path: ./github_artifacts/*
deploy:
needs: [build]
runs-on: ubuntu-latest
environment: deploy-logos
if: ${{ github.ref == 'refs/heads/corporate-design' }}
steps:
- uses: actions/download-artifact@v4
with:
path: github_artifacts
- name: Deploy
uses: peaceiris/actions-gh-pages@v4
with:
deploy_key: ${{ secrets.ACTIONS_DEPLOY_KEY }}
publish_dir: ./github_artifacts/logo_files
commit_message: "Generated logos"
user_name: "github-actions[bot]"
user_email: "41898282+github-actions[bot]@users.noreply.github.com"
enable_jekyll: true
publish_branch: logos
force_orphan: true
46 changes: 46 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/bin/bash

FILES = $(shell grep -Po "^logo_[^:]+(?=:)" Makefile)

all:
make $(FILES)

list:
@echo $(FILES)

logo_plain.svg: logo.svg Makefile
inkscape --actions="export-filename:$@; export-area-page; export-text-to-path; export-plain-svg; export-do;" $<

logo_sepia.png: logo.svg Makefile
inkscape --actions="export-filename:$@; export-area-page; export-dpi:192; export-do;" $<

logo_sepia.eps: logo.svg Makefile
inkscape --actions="export-filename:$@; export-area-page; export-do;" $<

logo_sepia.pdf: logo.svg Makefile
inkscape --actions="export-filename:$@; export-area-page; export-text-to-path; export-do;" $<

logo_white.png: logo.svg Makefile
inkscape --actions="export-filename:$@; export-area-page; export-id:layer1; export-id-only; export-background:white; export-dpi:192; export-do;" $<

logo_white.eps: logo.svg Makefile
inkscape --actions="export-filename:$@; export-area-page; export-id:layer1; export-id-only; export-background:white; export-do;" $<

logo_white.pdf: logo.svg Makefile
inkscape --actions="export-filename:$@; export-area-page; export-id:layer1; export-id-only; export-background:white; export-do;" $<

logo_transparent.png: logo.svg Makefile
inkscape --actions="export-filename:$@; export-area-page; export-id:layer1; export-id-only; export-dpi:192; export-do;" $<

temp_logo_banner_base.svg: logo.svg Makefile
inkscape --actions="export-filename:$@; select-by-id:text286611; transform-translate:700,-205; export-id:layer1; export-id-only; export-plain-svg; export-do;" $<
sed -i '/font-size:22.5778px/,$${s//font-size:67.60740px/;b};$$q1' $@

logo_banner.png: temp_logo_banner_base.svg Makefile
inkscape --actions="export-filename:$@; export-id:layer1; export-dpi:48; export-do;" $<

logo_banner_dark_mode.png: temp_logo_banner_base.svg Makefile
cp $< $@.svg
sed -i '/text-anchor:middle;fill:#3d2c25/,$${s//text-anchor:middle;fill:#eaeaea/;b};$$q1' $@.svg
inkscape --actions="export-filename:$@; export-id:layer1; export-dpi:48; export-do;" $@.svg
rm $@.svg
50 changes: 50 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Corporate design

The main logo is [logo.svg](logo.svg).

All derived logos can be regenerated with `make all`.
To create a new logo derived from the main one, add an extra target in the Makefile.
Use [Inkscape Actions](https://gist.github.com/jasonm23/c323bc20380d5569de68de23ee8d2ffa)
to transform individual elements of the SVG file.

## Continuous deployment

The generated files are automatically deployed to branch `logos`. This is achieved
using [GitHub Pages action](https://github.com/marketplace/actions/github-pages-action)
with a deployment token[^peaceiris-actions-gh-pages-faq-ssh].

To regenerate the deploy key and deployment secret, follow these steps:

1. create a new passwordless public/private key pair with this command[^github-docs-ssh]:
```sh
ssh-keygen -t ed25519 -f gh-pages -N "" -C "41898282+github-actions[bot]@users.noreply.github.com"
cat ./gh-pages.pub
cat ./gh-pages
```
2. create a new repository deploy key to store the public key[^github-docs-deploy-keys]
* got to the repository settings
* click "Deploy keys"
* click "Add deploy key"
* write `deploy-logos` in the "Title" field
* copy-paste the contents of `./gh-pages.pub` in the "Key" field
* check the "Allow write access" box
* click "Add key".
3. create a new repository environment to store the private key[^github-docs-env-secrets]
* go to the repository settings
* click "Environments"
* click "New environments"
* enter name `deploy-logos`
* click "Configure environment"
* in "Deployment branches and tags", click "No restriction" and "Selected branches and tags"
* click "Add deployment branch or tag rule"
* enter name pattern `corporate-design`
* click "Add rule"
* click "Add environment secret"
* write `ACTIONS_DEPLOY_KEY` in the "Name" field
* copy-paste the contents of `./gh-pages` in the "Value" field
* click "Add secret"

[^peaceiris-actions-gh-pages-faq-ssh]: FAQ section [Create SSH Deploy Key](https://github.com/peaceiris/actions-gh-pages/tree/v4.0.0?tab=readme-ov-file#tips-and-faq) explains the steps to register a SSH public/private key pair.
[^github-docs-ssh]: GitHub documentation: [Generating a new SSH key](https://docs.github.com/en/authentication/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent#generating-a-new-ssh-key) shows the exact command line options, in particular which algorithm to choose.
[^github-docs-deploy-keys]: GitHub documentation: [Set up deploy keys](https://docs.github.com/en/authentication/connecting-to-github-with-ssh/managing-deploy-keys#set-up-deploy-keys)
[^github-docs-env-secrets]: GitHub documentation: [Creating secrets for an environment](https://docs.github.com/en/actions/security-guides/using-secrets-in-github-actions#creating-secrets-for-an-environment)
22 changes: 14 additions & 8 deletions logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit c54f7d9

Please sign in to comment.