chore(ci): Add CI to run generate-genesis-template
after each build
#1
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build and Generate Genesis Template | |
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
# Step 1: Checkout the code | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
# Step 2: Set up Go | |
- name: Set up Go | |
uses: actions/setup-go@v5 | |
with: | |
go-version-file: 'go.mod' | |
# Step 3: Install dependencies | |
- name: Install dependencies | |
run: go mod tidy | |
# Step 4: Build the project | |
- name: Build project | |
run: go build ./... | |
# Step 5: Check for changes and commit | |
- name: Configure Git | |
run: | | |
git config --global user.email "github-actions[bot]@users.noreply.github.com" | |
git config --global user.name "github-actions[bot]" | |
- name: Check if "generate-genesis-template" branch exists | |
id: check_branch | |
run: | | |
if [ -n "$(git ls-remote --heads origin generate-genesis-template)" ]; then | |
git fetch origin generate-genesis-template | |
echo "branch_exists=true" >> $GITHUB_ENV | |
else | |
echo "branch_exists=false" >> $GITHUB_ENV | |
fi | |
# Step 6: Run generate-genesis-template | |
- name: Generate Genesis Template and update if branch exists | |
run: | | |
make generate-genesis | |
if [ "$branch_exists" == "true" ]; then | |
git checkout generate-genesis-template | |
git merge main --strategy-option theirs --allow-unrelated-histories --no-edit | |
git add . | |
git commit -m "generate genesis template [skip ci]" | |
git push origin generate-genesis-template | |
exit 0 | |
else | |
git checkout main | |
git checkout -b generate-genesis-template | |
git push origin generate-genesis-template | |
fi | |
# Step 7: Create pull request | |
- name: Create Pull Request | |
if: env.branch_exists == 'false' | |
id: cpr | |
uses: peter-evans/create-pull-request@v6 | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
commit-message: "Generate genesis template [skip ci]" | |
title: "Chore: Generate genesis template [skip ci]" | |
body: "Generate genesis template with recent pushes to branch main." | |
base: "main" | |
branch: "generate-genesis-template" | |
delete-branch: true | |
- name: Check outputs | |
if: env.branch_exists == 'false' | |
run: | | |
echo "Pull Request Number - ${{ steps.cpr.outputs.pull-request-number }}" | |
echo "Pull Request URL - ${{ steps.cpr.outputs.pull-request-url }}" | |
- name: Log if PR updated | |
if: steps.cpr.outputs.pull-request-operation == 'updated' | |
run: | | |
echo "Generate genesis template." |