forked from apollodao/cw-dex
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update CI/scripts to match template repo (apollodao#127)
* ci: Update to match template repo Updates the scripts and workflows to match those in the `apollo-template` repo. Signed-off-by: Bobby <[email protected]> * ci: Add todo script to Makefile.toml Signed-off-by: Bobby <[email protected]> * ci: Fix discrepancy in clippy usage Fixes a discrepancy between how clippy is used in Makefile.toml and in the lint-format.yml workflow Signed-off-by: Bobby <[email protected]> * ci: updates to template --------- Signed-off-by: Bobby <[email protected]> Co-authored-by: Sturdy <[email protected]>
- Loading branch information
1 parent
97b88f5
commit 1c2bdcd
Showing
13 changed files
with
171 additions
and
92 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
name: Test | ||
name: Test Suite | ||
on: | ||
pull_request: | ||
workflow_dispatch: | ||
|
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ target | |
.idea | ||
.vscode | ||
docs | ||
**/*.tmp |
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
#!/bin/bash | ||
# Script for syncing branch protection rules between repos. | ||
# By default copies rules from the `apollo-template` repo to specified branch in the current repo. | ||
|
||
if [[ -z $1 || -z $2 ]]; then | ||
echo "Usage: ./bpsync.sh <GitHub PAT> <target repo> <target branch>" | ||
exit 1 | ||
fi | ||
|
||
# Dependency check | ||
DEPS=(jq curl) | ||
for dep in $DEPS; do | ||
if [ ! $(which $dep) ]; then | ||
echo "'$dep' is not installed. Exiting." | ||
exit 1 | ||
fi | ||
done | ||
|
||
# personal access token | ||
PAT=$1 | ||
# source/target branch for copying protection rules | ||
BRANCH=$2 | ||
|
||
SRC_OWNER=apollodao | ||
SRC_REPO=apollo-template | ||
SRC_BRANCH=$BRANCH | ||
SRC_PAT=$PAT | ||
|
||
TGT_OWNER=apollodao | ||
TGT_REPO=$(basename $(git rev-parse --show-toplevel)) | ||
TGT_BRANCH=$BRANCH | ||
TGT_PAT=$PAT | ||
|
||
# GET branch protection rules | ||
HTTP_RESP=$(curl \ | ||
-H "Accept: application/vnd.github+json" \ | ||
-H "Authorization: Bearer ${SRC_PAT}"\ | ||
-H "X-GitHub-Api-Version: 2022-11-28" \ | ||
-w '%{http_code}' \ | ||
-o GET_response.tmp \ | ||
https://api.github.com/repos/$SRC_OWNER/$SRC_REPO/branches/$SRC_BRANCH/protection \ | ||
2>/dev/null | ||
) | ||
|
||
if [ $HTTP_RESP != 200 ]; then | ||
echo "Failed to get branch protection rules!" | ||
printf "HTTP Response %s\n" $HTTP_RESP | ||
exit 1 | ||
fi | ||
|
||
echo "Successfully fetched branch protection rules!" | ||
|
||
# Prepare branch protection rules for PUT request | ||
PAYLOAD=$( | ||
cat GET_response.tmp \ | ||
| jq -c \ | ||
'del( | ||
.required_signatures, # Delete "required_signatures" | ||
..| # Recurse.. | ||
.url?, # ..and delete "url", | ||
.contexts_url?, # "contexts_url" and "contexts" | ||
.contexts? # fields in the JSON | ||
) | ||
| walk( # Recurse again and flatten | ||
# objects with one field | ||
if type == "object" and length == 1 then | ||
.[] | ||
else | ||
. | ||
end | ||
) | ||
| .restrictions |= null # Add "restrictions" field' | ||
) | ||
|
||
# Try updating branch protection with shiny new JSON payload | ||
HTTP_RESP=$(curl \ | ||
-X PUT \ | ||
-H "Accept: application/vnd.github+json" \ | ||
-H "Authorization: Bearer ${TGT_PAT}"\ | ||
-H "X-GitHub-Api-Version: 2022-11-28" \ | ||
-w '%{http_code}' \ | ||
-o PUT_response.tmp \ | ||
https://api.github.com/repos/$TGT_OWNER/$TGT_REPO/branches/$TGT_BRANCH/protection \ | ||
-d "${PAYLOAD}" \ | ||
2>/dev/null | ||
) | ||
|
||
if [ $HTTP_RESP != 200 ]; then | ||
echo "Failed to copy branch protection rules!" | ||
echo "HTTP Response ${HTTP_RESP}" | ||
echo "ERROR MESSAGE: $(cat PUT_response.tmp | jq '.message')" | ||
exit 1 | ||
fi | ||
|
||
echo "Successfully copied branch protection rules!" | ||
# Clean up responses if successful | ||
rm GET_response.tmp PUT_response.tmp | ||
exit 0 |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#!/bin/sh | ||
|
||
# Escape codes | ||
RESET="\x1b[0m" | ||
RED="\x1b[31;49m" | ||
GREEN="\x1b[32;49m" | ||
BD="\x1b[39;49;1m" | ||
IT="\x1b[39;49;3m" | ||
UL="\x1b[39;49;4m" | ||
|
||
# if path is supplied as argument | ||
if [[ ! -z $1 && -d $1 ]]; then | ||
GREP_DIR=$1 | ||
echo "${BD}Searching in '$RESET$UL$GREP_DIR$RESET$BD'...$RESET" | ||
else | ||
GREP_DIR="." | ||
echo "${BD}No path supplied. Defaulting to current working directory...$RESET" | ||
fi | ||
|
||
# Regex | ||
LINT="todo[^!]" | ||
FORMAT="s/\.\/([a-zA-Z0-9_/.-]+):([0-9]+):(.+)/$UL\1$RESET ${BD}@ line \2:$RESET\n\t$IT$RED\3$RESET/" | ||
|
||
N=$(grep -riIo --include=*.{rs,toml,md,ts,js} -E $LINT $GREP_DIR | wc -l | xargs) | ||
|
||
|
||
if [ $N -gt 0 ]; then | ||
echo "${BD}Found $UL$RED$N$RESET$BD occurrences matching pattern '$RESET$IT$LINT$RESET$BD':$RESET" | ||
echo "------------------------------------------------" | ||
grep -rniI --include=*.{rs,toml,md,ts,js} -E $LINT $GREP_DIR | sed -E "$FORMAT" | ||
exit 1 | ||
fi | ||
|
||
echo "${GREEN}No occurrences of pattern '$IT$LINT$RESET$GREEN' found!$RESET" | ||
exit 0 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,4 +7,4 @@ exclude-files=[ | |
] | ||
fail-under=0 # TODO: update this | ||
no-fail-fast=true | ||
skip-clean=false | ||
skip-clean=false |