Skip to content

Commit

Permalink
Merge pull request #187 from shutter-network/staging
Browse files Browse the repository at this point in the history
Staging
  • Loading branch information
ylembachar authored Oct 24, 2024
2 parents 5492806 + 4620c2c commit 4f1d038
Show file tree
Hide file tree
Showing 8 changed files with 266 additions and 103 deletions.
231 changes: 170 additions & 61 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,66 +3,175 @@ name: Build and Deploy
on:
push:
branches:
- main
- staging
- main
- staging
pull_request:
branches:
- main
- staging

jobs:
run_cypress_tests:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Install Node.js
uses: actions/setup-node@v3
with:
node-version: '20.12.2'

- name: Install dependencies
run: |
cd frontend
npm install
- name: Run Cypress component tests
run: |
cd frontend
npx cypress run --component
deploy_instance_staging:
if: github.ref == 'refs/heads/staging'
runs-on: ubuntu-latest
needs: run_cypress_tests

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Setup SSH
run: |
mkdir -p ~/.ssh
echo "${{ secrets.SERVER_KEY }}" > ~/.ssh/id_ed25519 && chmod 600 ~/.ssh/id_ed25519
- name: Deploy to Staging
run: >
ssh -o StrictHostKeyChecking=no ${{secrets.STAGING_SERVER_USER}}@${{secrets.STAGING_SERVER_HOST}}
"set -x && cd /root/shutter-explorer && git pull origin staging && git submodule update --init --recursive && cd docker && docker compose up -d --build"
deploy_instance_prod:
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
needs: run_cypress_tests

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Setup SSH
run: |
mkdir -p ~/.ssh
echo "${{ secrets.SERVER_KEY }}" > ~/.ssh/id_ed25519 && chmod 600 ~/.ssh/id_ed25519
- name: Deploy to Production
run: >
ssh -o StrictHostKeyChecking=no ${{secrets.PROD_SERVER_USER}}@${{secrets.PROD_SERVER_HOST}}
"set -x && cd /root/shutter-explorer && git pull origin main && git submodule update --init --recursive && cd docker && docker compose up -d --build"
run_cypress_tests:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Install Node.js
uses: actions/setup-node@v3
with:
node-version: "20.12.2"

- name: Install dependencies
run: |
cd frontend
npm install
- name: Run Cypress component tests
run: |
cd frontend
npx cypress run --component
# Branch Name Validation for Pull Requests
validate_branch_name:
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
steps:
- name: Validate branch name
run: |
BRANCH_NAME="${{ github.head_ref }}"
echo "Validating branch name: $BRANCH_NAME"
# Allow 'staging' and 'main' branches
if [[ "$BRANCH_NAME" == "staging" || "$BRANCH_NAME" == "main" ]]; then
exit 0
fi
# Check if the branch name starts with the expected prefixes
if [[ "$BRANCH_NAME" == release/* ]] || [[ "$BRANCH_NAME" == feat/* ]] || [[ "$BRANCH_NAME" == fix/* ]] || [[ "$BRANCH_NAME" == chore/* ]] || [[ "$BRANCH_NAME" == docs/* ]] || [[ "$BRANCH_NAME" == test/* ]]; then
echo "Branch name is valid: $BRANCH_NAME"
else
echo "Error: Branch name must start with 'release/', 'feat/', 'fix/', 'chore/', 'docs/', or 'test/'."
exit 1 # Exit if the branch name is not valid
fi
# Staging Deployment (with Tagging)
deploy_instance_staging:
if: github.ref == 'refs/heads/staging' && github.event_name == 'push'
runs-on: ubuntu-latest
needs: run_cypress_tests

steps:
- name: Checkout code
uses: actions/checkout@v3

# Fetch tags to get the latest version tag
- name: Fetch tags
run: git fetch --tags

# Install semver for version bumping
- name: Install semver
run: npm install -g semver

# Determine version bump after a merge to staging
- name: Determine version bump
id: version_bump
run: |
# Get the latest tag (assuming semantic versioning format v1.2.3)
LATEST_TAG=$(git describe --tags $(git rev-list --tags --max-count=1))
# Default version bump is patch
VERSION_BUMP="patch"
# Find the source branch by checking the latest merge commit
SOURCE_BRANCH=$(git log -1 --pretty=%B | grep -oP '(?<=from\s)[^\s]+')
# Remove the 'shutter-network/' prefix if it exists
CLEANED_SOURCE_BRANCH=$(echo "$SOURCE_BRANCH" | sed 's/^shutter-network\///')
echo "Source branch: $CLEANED_SOURCE_BRANCH"
# Allow 'staging' and 'main' branches without version bump
if [[ "$CLEANED_SOURCE_BRANCH" == "staging" || "$CLEANED_SOURCE_BRANCH" == "main" ]]; then
echo "No version bump required for 'staging' or 'main' branch."
exit 0
fi
# Determine version bump based on the source branch
if [[ "$CLEANED_SOURCE_BRANCH" == release/* ]]; then
VERSION_BUMP="major"
elif [[ "$CLEANED_SOURCE_BRANCH" == feat/* ]]; then
VERSION_BUMP="minor"
elif [[ "$CLEANED_SOURCE_BRANCH" == fix/* ]]; then
VERSION_BUMP="patch"
elif [[ "$CLEANED_SOURCE_BRANCH" == chore/* ]]; then
VERSION_BUMP="patch"
elif [[ "$CLEANED_SOURCE_BRANCH" == docs/* ]]; then
VERSION_BUMP="patch"
elif [[ "$CLEANED_SOURCE_BRANCH" == test/* ]]; then
VERSION_BUMP="patch"
else
echo "Error: Source branch name must start with 'release/', 'feat/', 'fix/', 'chore/', 'docs/' or 'test/'."
exit 1
fi
# Calculate the next version using semver
NEXT_VERSION=$(npx semver "$LATEST_TAG" -i $VERSION_BUMP)
echo "NEXT_VERSION=$NEXT_VERSION" >> $GITHUB_ENV
echo "Next version: $NEXT_VERSION"
# Create a new tag for the staging deployment
- name: Create and push new version tag
if: env.NEXT_VERSION != ''
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git tag "v${{ env.NEXT_VERSION }}"
git push origin "v${{ env.NEXT_VERSION }}"
# Setup SSH for deployment
- name: Setup SSH
run: |
mkdir -p ~/.ssh
echo "${{ secrets.SERVER_KEY }}" > ~/.ssh/id_ed25519 && chmod 600 ~/.ssh/id_ed25519
# Deploy to Staging
- name: Deploy to Staging
run: >
ssh -o StrictHostKeyChecking=no ${{secrets.STAGING_SERVER_USER}}@${{secrets.STAGING_SERVER_HOST}}
"set -x && cd /root/shutter-explorer && git pull origin staging && git submodule update --init --recursive && cd docker && docker compose up -d --build"
# Production Deployment (using the tag from staging)
deploy_instance_prod:
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
runs-on: ubuntu-latest
needs: run_cypress_tests

steps:
- name: Checkout code
uses: actions/checkout@v3

# Fetch tags to get the latest version tag from staging
- name: Fetch tags
run: git fetch --tags

# Get the latest tag from staging
- name: Get latest version tag
id: get_latest_tag
run: |
LATEST_TAG=$(git describe --tags $(git rev-list --tags --max-count=1))
echo "LATEST_TAG=$LATEST_TAG" >> $GITHUB_ENV
# Setup SSH for deployment
- name: Setup SSH
run: |
mkdir -p ~/.ssh
echo "${{ secrets.SERVER_KEY }}" > ~/.ssh/id_ed25519 && chmod 600 ~/.ssh/id_ed25519
# Deploy to Production with the latest tag from staging
- name: Deploy to Production
run: >
ssh -o StrictHostKeyChecking=no ${{secrets.PROD_SERVER_USER}}@${{secrets.PROD_SERVER_HOST}}
"set -x && cd /root/shutter-explorer && git pull origin main && git submodule update --init --recursive && git checkout tags/${{ env.LATEST_TAG }} && cd docker && docker compose up -d --build"
60 changes: 43 additions & 17 deletions backend/internal/data/shutter_explorer.sql.go

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

38 changes: 25 additions & 13 deletions backend/internal/data/sql/queries/shutter_explorer.sql
Original file line number Diff line number Diff line change
Expand Up @@ -139,26 +139,38 @@ SELECT tx_hash, EXTRACT(EPOCH FROM created_at)::BIGINT AS included_timestamp
FROM decrypted_tx
WHERE slot = $1 AND tx_status = 'shielded inclusion';

-- name: QueryFromTransactionDetails :one
-- name: QueryFromTransactionDetails :many
SELECT tx_hash as user_tx_hash, encrypted_tx_hash
FROM transaction_details
WHERE tx_hash = $1 OR encrypted_tx_hash = $1
ORDER BY submission_time DESC
LIMIT 1;
ORDER BY submission_time DESC;

-- name: QueryTransactionDetailsByTxHash :one
SELECT
tse.event_tx_hash, tse.sender, FLOOR(EXTRACT(EPOCH FROM tse.created_at)) as created_at_unix, tse.created_at,
dt.tx_hash AS user_tx_hash, dt.tx_status, dt.slot,
COALESCE(FLOOR(EXTRACT(EPOCH FROM dt.created_at)), 0)::BIGINT AS decrypted_tx_created_at_unix,
COALESCE(FLOOR(EXTRACT(EPOCH FROM dt.updated_at)), 0)::BIGINT AS decrypted_tx_updated_at_unix,
bk.block_number as block_number
FROM transaction_submitted_event tse
LEFT JOIN decrypted_tx dt ON tse.id = dt.transaction_submitted_event_id
LEFT JOIN block bk ON dt.slot = bk.slot
WHERE tse.event_tx_hash = $1 OR dt.tx_hash = $1
WITH prioritized_tx AS (
SELECT
tse.event_tx_hash, tse.sender,
FLOOR(EXTRACT(EPOCH FROM tse.created_at)) AS created_at_unix,
tse.created_at,
dt.tx_hash AS user_tx_hash, dt.tx_status, dt.slot,
COALESCE(FLOOR(EXTRACT(EPOCH FROM dt.created_at)), 0)::BIGINT AS decrypted_tx_created_at_unix,
COALESCE(FLOOR(EXTRACT(EPOCH FROM dt.updated_at)), 0)::BIGINT AS decrypted_tx_updated_at_unix,
bk.block_number AS block_number,
CASE
WHEN dt.tx_status = 'shielded inclusion' THEN 1
WHEN dt.tx_status = 'unshielded inclusion' THEN 2
ELSE 3
END AS priority
FROM transaction_submitted_event tse
LEFT JOIN decrypted_tx dt ON tse.id = dt.transaction_submitted_event_id
LEFT JOIN block bk ON dt.slot = bk.slot
WHERE tse.event_tx_hash = $1 OR dt.tx_hash = $1
)
SELECT *
FROM prioritized_tx
ORDER BY priority
LIMIT 1;


-- name: QueryLatestSequencerTransactions :many
SELECT ('0x' || encode(event_tx_hash, 'hex'))::TEXT AS sequencer_tx_hash, FLOOR(EXTRACT(EPOCH FROM created_at)) as created_at_unix
FROM transaction_submitted_event
Expand Down
Loading

0 comments on commit 4f1d038

Please sign in to comment.