Skip to content

Commit

Permalink
Merge pull request #176 from teogor/plugin/winds-impl
Browse files Browse the repository at this point in the history
[ENV]: Build automation with the Winds plugin
  • Loading branch information
teogor authored Nov 23, 2023
2 parents 1185ffc + ec05dde commit df869c3
Show file tree
Hide file tree
Showing 85 changed files with 3,916 additions and 2,213 deletions.
78 changes: 0 additions & 78 deletions .github/workflows/android.yml

This file was deleted.

158 changes: 158 additions & 0 deletions .github/workflows/deploy-docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
name: Docs Deployment

on:
workflow_dispatch:
push:
branches:
- main

permissions:
contents: write
pages: write
id-token: write
pull-requests: write

# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
concurrency:
group: "api-docs"
cancel-in-progress: false

env:
OWNER: teogor
DESTINATION_BRANCH: docs/teogor/${{ github.event.repository.name }}/${{ github.sha }}
REPOSITORY: ${{ github.event.repository.name }}
REPO: teogor/${{ github.event.repository.name }}
DISPLAY_NAME: Ceres

jobs:
synchronize-documentation:
runs-on: ubuntu-latest
name: Synchronize Repository Documentation
steps:
- uses: actions/checkout@v4

# Grants execute permission to gradle (safety step)
- name: Grant Permissions to gradlew
run: chmod +x gradlew

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.x

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install mkdocs-material
pip install mkdocs-material[recommended,git,imaging]
- name: Build MkDocs
run: |
mkdocs build --clean
mkdocs --version
- name: Setup Java
uses: actions/setup-java@v3
with:
distribution: temurin
java-version: 17

- name: Generate Backup's API Documentation
run: ./gradlew -D'org.gradle.unsafe.configuration-cache=false' :backup:dokkaHtmlMultiModule

- name: Generate Core's API Documentation
run: ./gradlew -D'org.gradle.unsafe.configuration-cache=false' :core:dokkaHtmlMultiModule

- name: Generate Data's API Documentation
run: ./gradlew -D'org.gradle.unsafe.configuration-cache=false' :data:dokkaHtmlMultiModule

- name: Generate Firebase's API Documentation
run: ./gradlew -D'org.gradle.unsafe.configuration-cache=false' :firebase:dokkaHtmlMultiModule

- name: Generate Framework's API Documentation
run: ./gradlew -D'org.gradle.unsafe.configuration-cache=false' :framework:dokkaHtmlMultiModule

- name: Generate Monetisation's API Documentation
run: ./gradlew -D'org.gradle.unsafe.configuration-cache=false' :monetisation:dokkaHtmlMultiModule

- name: Generate Navigation's API Documentation
run: ./gradlew -D'org.gradle.unsafe.configuration-cache=false' :navigation:dokkaHtmlMultiModule

- name: Generate Screen's API Documentation
run: ./gradlew -D'org.gradle.unsafe.configuration-cache=false' :screen:dokkaHtmlMultiModule

- name: Generate UI's API Documentation
run: ./gradlew -D'org.gradle.unsafe.configuration-cache=false' :ui:dokkaHtmlMultiModule

- name: Relocate API References
run: |
mkdir -p build/docs/${{ env.REPOSITORY }}/reference
cp -r build/reference/* build/docs/${{ env.REPOSITORY }}/reference
- id: publish-docs
name: Deploy Documentation
uses: ./.github/workflows/sync-docs/
env:
API_TOKEN_GITHUB: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
with:
source-file: build/docs/${{ env.REPOSITORY }}/
destination-folder: ${{ env.REPOSITORY }}
destination-repo: teogor/source.teogor.dev
user-email: [email protected]
user-name: Teodor Grigor
destination-branch-create: ${{ env.DESTINATION_BRANCH }}

build-and-deploy:
needs: synchronize-documentation
name: Build and Deploy Updated API Documentation
runs-on: ubuntu-latest
steps:
- name: Checkout other repository
uses: actions/checkout@v3
with:
repository: teogor/source.teogor.dev
token: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
ref: ${{ env.DESTINATION_BRANCH || 'main' }}
# This is important to fetch the changes to the previous commit
fetch-depth: 0

# - name: Prettify code
# uses: creyD/[email protected]
# with:
# # This part is also where you can pass other options, for example:
# prettier_options: --write ${{ env.REPOSITORY }}/**/*.{js,html,css,json}
# only_changed: False
# same_commit: True

- name: Create PR (Pull Request)
run: |
json=$(curl -L \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.PERSONAL_ACCESS_TOKEN }}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/teogor/source.teogor.dev/pulls \
-d '{
"title":"Updated documentation for `${{ env.REPO }}`",
"body":"## 🚀 **Updated Documentation for ${{ env.DISPLAY_NAME }}** 🚀\n\nThis pull request brings you the latest updates to the [${{ env.DISPLAY_NAME }}](https://github.com/${{ env.REPO }}) documentation, ensuring you have access to the most comprehensive and informative guide for using this powerful library.\n\n-------\n\n* Generated by [Publish Docs](https://github.com/${{ env.REPO }}/actions/workflows/publish-docs.yml)\n\n* From [${{ env.REPO }}](https://github.com/${{ env.REPO }})",
"head":"${{ env.DESTINATION_BRANCH }}",
"base":"main"
}' | jq .)
number=$(jq '.number' <<< ${json})
curl -L \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.PERSONAL_ACCESS_TOKEN }}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/teogor/source.teogor.dev/issues/${number}/labels \
-d '{"labels":["@documentation"]}'
curl -L \
-X PUT \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.PERSONAL_ACCESS_TOKEN }}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/teogor/source.teogor.dev/pulls/${number}/merge \
65 changes: 65 additions & 0 deletions .github/workflows/sync-docs/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: 'Publish Docs'
description: 'Comprehensive publish docs'
branding:
icon: 'git-commit'
color: 'red'
inputs:
source-file:
description: 'Source file from the origin directory'
required: true
destination-repo:
description: 'Destination repository'
required: true
destination-folder:
description: 'Directory to push the file to'
required: false
user-email:
description: 'Email for the git commit'
required: true
user-name:
description: 'GitHub username for the commit'
required: true
destination-branch:
description: 'branch to push file to, defaults to main'
required: false
destination-branch-create:
description: 'Destination branch to create for this commit'
required: false
commit-message:
description: 'A custom message for the commit'
required: false
rename:
description: 'Rename the destination file'
required: false
use-rsync:
description: 'Copy files/directories using rsync instead of cp. Experimental feature, please know your use case'
required: false
git-server:
description: 'Git server host, default github.com'
required: false
default: github.com
runs:
using: "composite"
steps:
- name: Make all .sh files executable
run: find . -type f -name "*.sh" -exec chmod +x {} \;
shell: bash

- run: echo "${{ github.action_path }}" >> $GITHUB_PATH
shell: bash

- name: Execute Entrypoint Script
shell: bash
env:
SOURCE_FILE: ${{ inputs.source-file }}
DESTINATION_REPO: ${{ inputs.destination-repo }}
DESTINATION_FOLDER: ${{ inputs.destination-folder }}
USER_EMAIL: ${{ inputs.user-email }}
USER_NAME: ${{ inputs.user-name }}
DESTINATION_BRANCH: ${{ inputs.destination-branch }}
DESTINATION_BRANCH_CREATE: ${{ inputs.destination-branch-create }}
COMMIT_MESSAGE: ${{ inputs.commit-message }}
GIT_SERVER: ${{ inputs.git-server }}
RENAME: ${{ inputs.rename }}
USE_RSYNC: ${{ inputs.use-rsync }}
run: sync-files.sh
78 changes: 78 additions & 0 deletions .github/workflows/sync-docs/sync-files.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#!/bin/sh

set -e
set -x

# Validate required input
if [ -z "$SOURCE_FILE" ]; then
echo "Error: Source file must be specified."
exit 1
fi

# Set default values for optional variables
if [ -z "$GIT_SERVER" ]; then
GIT_SERVER="github.com"
fi

if [ -z "$DESTINATION_BRANCH" ]; then
DESTINATION_BRANCH="main"
fi

# Clone the destination Git repository
OUTPUT_BRANCH="$DESTINATION_BRANCH"

CLONE_DIR=$(mktemp -d)
echo "Cloning destination Git repository: $DESTINATION_REPO"

git config --global user.email "$USER_EMAIL"
git config --global user.name "$USER_NAME"

git clone --single-branch --branch $DESTINATION_BRANCH "https://x-access-token:$API_TOKEN_GITHUB@$GIT_SERVER/$DESTINATION_REPO.git" "$CLONE_DIR"

# Determine the destination file path
DEST_COPY="$CLONE_DIR/$DESTINATION_FOLDER/"

if [ ! -z "$RENAME" ]; then
echo "Renaming file to: ${RENAME}"
DEST_COPY="$CLONE_DIR/$DESTINATION_FOLDER/$RENAME"
fi

# Delete the previous folder if it exists
if [ -d "$DEST_COPY" ]; then
echo "Deleting existing folder: $DEST_COPY"
rm -rf "$DEST_COPY"
fi

# Copy the source file to the destination repository
echo "Copying contents to Git repo: $SOURCE_FILE"

# Move the source file instead of copying it to avoid creating duplicates
cp -r "$SOURCE_FILE" "$DEST_COPY"

# Check out the specified branch or create a new one
cd "$CLONE_DIR"

if [ ! -z "$DESTINATION_BRANCH_CREATE" ]; then
echo "Creating new branch: $DESTINATION_BRANCH_CREATE"
git checkout -b "$DESTINATION_BRANCH_CREATE"
OUTPUT_BRANCH="$DESTINATION_BRANCH_CREATE"
fi

if [ -z "$COMMIT_MESSAGE" ]; then
COMMIT_MESSAGE="Automated updates based on https://$GIT_SERVER/${GITHUB_REPOSITORY}/commit/${GITHUB_SHA}"
fi

# Add the copied file to the staging area
echo "Adding git commit"
git add .

# Commit changes if there are any
if git status | grep -q "Changes to be committed"; then
echo "Committing changes with message: $COMMIT_MESSAGE"
git commit --message "$COMMIT_MESSAGE"

echo "Pushing git commit to branch: $OUTPUT_BRANCH"
git push -u origin HEAD:"$OUTPUT_BRANCH"
else
echo "No changes detected, skipping commit and push"
fi
4 changes: 4 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit df869c3

Please sign in to comment.