Skip to content

Commit

Permalink
Merge pull request #354 from celestiaorg/sevey/ci
Browse files Browse the repository at this point in the history
feat: add CI for validating genesis and PR users
  • Loading branch information
MSevey authored Oct 21, 2023
2 parents 5ee6e38 + 14fb188 commit c695aed
Show file tree
Hide file tree
Showing 8 changed files with 1,380 additions and 0 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/10_utia_accounts.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
address,balance
celestia1r5xt7twqmh39ky72f4txxjrhlt2z0qww7jlx37,10
celestia1qx43f066sh6728avms4qq09cj2a3mg83ghswuv,10
celestia1uqj5ul7jtpskk9ste9mfv6jvh0y3w34vw7qg7g,10
celestia1demcj83q7nxt6gtqxlu7qsmwqpt4jspj5za6nv,10
celestia1ax83exaawlmy5p2qn22gcynrchwdntt5rnskk6,10
celestia1vje2he3pcq3w5udyvla7zm9qd5yes6hzvkjts5,10
celestia1c9ye54e3pzwm3e0zpdlel6pnavrj9qqvhxzwea,10
celestia1u4vhh70lwlt2va7hw5evzl6sap92t0m9klqz2t,10
celestia1v5hrqlv8dqgzvy0pwzqzg0gxy899rm4k6ayzec,10
celestia1xqc7w3pe38kg4tswjt7mnvks7gy4p38vw07aw5,10
celestia1yraa2gnhdlwms4keqq0gekv2ese6wteqfr6p0e,10
celestia187avawwq7qhanrkxf45mayztdqsr49huzqmmm3,10
celestia1uwmf03ke52vld2sa9khs0nslpgzwsm5x4tmvh4,10
celestia1v987evnk7hsqct7smdqpxqprhvlcxgt45fxqc7,10
celestia19y52qzj4hxw0u68krfptkjlm77cvth8ddre8j6,10
celestia12t63cy8kn5n7qw77xvjn00ymcr0uuvz2fg9cgr,10
celestia1slnzmhg3kwhc2c5y9atrt5jtmt3sauzzy2f325,10
celestia19v94c3z7ckarwsum76kaagma0wqsqhh5kqkmkw,10
celestia1e7jh5dt02ee5k6vrfls0ttuxyj9k0g5a42tl2q,10
celestia133t4gpv4vhpqgfn9gr8l4u423zrglg8rnlm9h9,10
celestia1st4h4ymu52hwtl3s0n298t6adj0vputxzdv7sd,10
celestia1qxeza0sa037u35p3ze8p7ka7emajvydnpdacec,10
celestia1pnzrk7yzx0nr9xrcjyswj7ram4qxlrfz0cy49u,10
celestia10f8l8m4879h40848rsvxat797t3a5ghgg0s35e,10
celestia14v4ush42xewyeuuldf6jtdz0a7pxg5fwxq7zc0,10
celestia1knn88yl08ctsdrtxvfp39jywt7rph9ptfpkguz,10
831 changes: 831 additions & 0 deletions .github/workflows/80_percent_accounts.csv

Large diffs are not rendered by default.

67 changes: 67 additions & 0 deletions .github/workflows/checkuser.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package main

import (
"encoding/csv"
"fmt"
"os"
)

func main() {
if len(os.Args) != 3 {
fmt.Println("Usage: checkuser <user> <pr>")
os.Exit(1)
}

user := os.Args[1]
pr := os.Args[2]

if err := checkUser(user, pr); err != nil {
fmt.Println(err)
os.Exit(1)
}
}

func checkUser(user string, pr string) error {
// Open the CSV file
file, err := os.OpenFile("./.github/workflows/usersprs.csv", os.O_RDWR|os.O_CREATE, 0644)
if err != nil {
return err
}
defer file.Close()

// Read the CSV file
r := csv.NewReader(file)
records, err := r.ReadAll()
if err != nil {
return err
}

// Check if the user exists in the CSV file
var userExists bool
for _, record := range records {
if record[0] == user {
userExists = true
if record[1] == pr {
fmt.Println("Pass: User exists with the same PR number")
return nil
} else {
fmt.Println("Fail: User exists with different PR number")
return fmt.Errorf("User %s already exists with PR number %s", user, record[1])
}
}
}

// If the user does not exist, add them to the CSV file
if !userExists {
w := csv.NewWriter(file)
defer w.Flush()

if err := w.Write([]string{user, pr}); err != nil {
return err
}

fmt.Printf("User %s added with PR number %s\n", user, pr)
}

return nil
}
2 changes: 2 additions & 0 deletions .github/workflows/usersprs.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
user,pr
MSevey,3
70 changes: 70 additions & 0 deletions .github/workflows/validate-genesis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
name: Validate Genesis
on:
pull_request:
push:
branches:
- main
jobs:
no-change:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Check for Genesis file changes
id: changed-genesis-files
uses: tj-actions/changed-files@v39
with:
files: "**/*genesis.json"

- name: Fail if any changes in genesis file
if: steps.changed-genesis-files.outputs.any_changed == 'true'
run: |
echo "change in genesis.json file detected!"
exit 1
appd-validate-genesis:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: 1.21
- name: Download celestiaorg/celestia-app
run: git clone https://github.com/celestiaorg/celestia-app.git
- name: Install Celestiaorg/celestia-app
run: cd celestia-app && make install
# Validation checks https://github.com/cosmos/cosmos-sdk/blob/bff3104781cca3c409fecfa3efebd80a40eb48c3/x/genutil/types/genesis.go#L53
- name: Validate Pre Genesis
run: |
if test -f ./celestia/pre-genesis.json; then
celestia-appd validate-genesis ./celestia/pre-genesis.json
fi
- name: Validate Genesis
run: |
if test -f ./celestia/genesis.json; then
celestia-appd validate-genesis ./celestia/genesis.json
fi
run-network:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: 1.21
- name: Download celestiaorg/celestia-app
run: git clone https://github.com/celestiaorg/celestia-app.git
- name: Checkout test branch and Install gentest util
run: |
cd celestia-app
git checkout evan/mainnet-tooling
cd cmd/celestia-appd/cmd/gentest
go install
- name: Validate Genesis
run: |
if test -f ./celestia/pre-genesis.json; then
gentest ./celestia/pre-genesis.json ./celestia/gentx
fi
94 changes: 94 additions & 0 deletions .github/workflows/validate-gentx.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
name: Validate Gentx
on:
pull_request:

jobs:
find-gentx-files:
runs-on: ubuntu-latest
outputs:
gentx-files: ${{ steps.set-outputs.outputs.gentx-files }}
gentx-changed: ${{ steps.set-outputs.outputs.gentx-changed }}
steps:
- uses: actions/checkout@v4
- name: Get changed gentx files
id: changed-files
uses: tj-actions/changed-files@v39
with:
files: "./celestia/*gentx*/*.json"
- name: Set outputs
id: set-outputs
run: |
echo "gentx-files=${{ steps.changed-files.outputs.all_changed_files }}" >> "$GITHUB_OUTPUT"
echo "gentx-changed=${{ steps.changed-files.outputs.any_changed }}" >> "$GITHUB_OUTPUT"
check-user-pr:
needs: find-gentx-files
runs-on: ubuntu-latest
permissions:
pull-requests: write
if: needs.find-gentx-files.outputs.gentx-changed == 'true'
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.ref }}
- name: Check user csv
id: check-user-pr
run: go run .github/workflows/checkuser.go ${{github.actor}} ${{github.event.number}}
- name: Commit changes to the csv
if: success()
uses: EndBug/add-and-commit@v9
with:
message: "Add ${{github.actor}} with pr ${{github.event.number}} to usersprs.csv file"
- name: Add comment about user in csv
if: failure()
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: 'User has previously submitted a gentx PR'
})
jq-format:
needs: find-gentx-files
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- uses: actions/checkout@v4
- name: List all changed files
run: |
for file in ${{ needs.find-gentx-files.outputs.gentx-files }}; do
jq . $file >$file"_tmp"
cmp -s $file"_tmp" $file || (echo "$file gentx file not formatted" && exit 1)
done
- name: Add comment about formatting failure
if: failure()
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: 'Please format your gentx by running `jq . path/to/gentx.json > path/to/gentx.json_tmp && mv path/to/gentx.json_tmp path/to/gentx.json` and resubmit the PR.'
})
valid-gentx:
needs: find-gentx-files
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: 1.21
- name: Validate addresses and a balances
run: |
for file in ${{ needs.find-gentx-files.outputs.gentx-files }}; do
go run .github/workflows/validate.go $file
done
Loading

0 comments on commit c695aed

Please sign in to comment.