Skip to content

Instantly share code, notes, and snippets.

@ksharma-xyz
Created July 6, 2024 11:51
Show Gist options
  • Save ksharma-xyz/9e3d32ba431cb5e3f980ec92edaa033f to your computer and use it in GitHub Desktop.
Save ksharma-xyz/9e3d32ba431cb5e3f980ec92edaa033f to your computer and use it in GitHub Desktop.
Generate Kotlin files and push them to new repository by creating a PR
name: Generate Kotlin
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
workflow_dispatch:
jobs:
generate-kotlin:
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v4
- name: List directory structure before building
run: ls -R
- name: Generate Protos
run: ./gradlew generateProtos
- name: Debug - List generated Kotlin files
run: |
files=$(find lib/build/generated/source/wire/ -type f -name '*.kt')
echo "Found files:"
echo "$files"
joined_files=$(echo "$files" | paste -sd ",")
echo "KOTLIN_FILES=$joined_files" >> $GITHUB_ENV
shell: bash
- name: Upload generated Kotlin files
id: upload-gen-kotlin-files
uses: actions/upload-artifact@v4
with:
name: generated-kotlin-files
path: lib/build/generated/source/wire/**/*.kt
- name: Checkout target repo
uses: actions/checkout@v4
with:
repository: 'ksharma-xyz/Kotlin-Proto'
token: ${{ secrets.TOKEN }}
- name: Download artifact
uses: actions/download-artifact@v4
with:
name: generated-kotlin-files
path: ./generated
- name: Get Unix Timestamp
id: get-timestamp
run: echo "TIMESTAMP=$(date +'%s')" >> $GITHUB_ENV
- name: Create Branch
run: |
timestamp=$(date +'%s')
branch_name="branch-${timestamp}"
git checkout -b $branch_name
git push origin $branch_name
echo "BRANCH_NAME=$branch_name" >> $GITHUB_ENV
- name: Create Pull Request
uses: peter-evans/create-pull-request@v6
with:
token: ${{ secrets.TOKEN }}
branch: ${{ env.BRANCH_NAME }}
committer: Github Actions Bot <41898282+github-actions[bot]@users.noreply.github.com>
author: Github Actions Bot <41898282+github-actions[bot]@users.noreply.github.com>
commit-message: "Add generated Kotlin files ${{ env.TIMESTAMP }}"
title: "Add generated Kotlin files ${{ env.TIMESTAMP }}"
body: |
### Description
Automated PR to add generated Kotlin files from [Proto-API](https://github.com/ksharma-xyz/Proto-API)
### Config
Configuration of the workflow is located in `.github/workflows/gen-kotlin.yaml`.
base: main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment