name: Generate Emojis to Rust
on:
workflow_dispatch:
inputs:
VERSION:
type: string
default: 3.14.0
description: Version of emojis to generate
BRANCH:
type: string
default: main
description: Specify branch to run
jobs:
fetch:
name: Get new version of emojis
runs-on: ubuntu-22.04
outputs:
content: ${{ steps.output_file.outputs.content }}
env:
VERSION: ${{ github.event.inputs.VERSION }}
steps:
- name: Fetch
id: output_file
run: |
wget "https://raw.githubusercontent.com/carloscuesta/gitmoji/v$VERSION/packages/gitmojis/src/gitmojis.json" -O gitmojis.json
content=$(jq --compact-output '.' gitmojis.json)
echo "content=$content" >> "$GITHUB_OUTPUT"
generate:
name: Generate Rust Code
needs: [fetch]
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.inputs.BRANCH }}
- name: Generate
env:
VERSION: ${{ github.event.inputs.VERSION }}
CONTENT: ${{ needs.fetch.outputs.content }}
run: |
N=$(echo "$CONTENT" | jq '.gitmojis | length')
cat >./src/gen/emojis.rs <<EOF
// Not manual modify
// This code is autogenerated by pipeline on GitHub Actions
// Version of emoji based: v$VERSION
// This generation is based from https://raw.githubusercontent.com/carloscuesta/gitmoji/v$VERSION/packages/gitmojis/src/gitmojis.json
use colored::*;
use serde::Deserialize;
#[derive(Deserialize, Clone)]
pub struct Emoji {
pub emoji: &'static str,
pub description: &'static str,
pub name: &'static str,
}
impl Emoji {
const fn new(emoji: &'static str, name: &'static str, description: &'static str) -> Self {
Self {
emoji,
name,
description,
}
}
}
impl std::fmt::Display for Emoji {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let name = format!("({})", self.name).bright_blue();
write!(f, "{} | {} {}", self.emoji, self.description, name)
}
}
pub const EMOJIS: [Emoji; $N] = [
EOF
echo "$CONTENT" | jq -c '.gitmojis[]' | while read -r e; do
name=$(echo "$e" | jq -c '.name')
emoji=$(echo "$e" | jq -c '.emoji')
description=$(echo "$e" | jq -c '.description')
echo -e "\tEmoji::new($emoji, $name, $description),">>./src/gen/emojis.rs
done
echo "];" >>./src/gen/emojis.rs
- uses: dtolnay/rust-toolchain@nightly
- uses: Swatinem/rust-cache@v2
- name: Rust Check
run: |
cargo check
- name: Deploy
env:
BRANCH: ${{ github.event.inputs.BRANCH }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_USER: "github-actions[bot]"
GITHUB_EMAIL: "github-actions[bot]@users.noreply.github.com"
run: |
git config --global user.name "${GITHUB_USER}"
git config --global user.email "${GITHUB_EMAIL}"
git add -A && git commit -m "build: updated emojis from generation"
git push origin $BRANCH