Skip to content

Commit

Permalink
Merge pull request #40 from gnosischain/dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Wagalidoom authored May 28, 2024
2 parents a0fa79e + 3236746 commit 3fa62c1
Show file tree
Hide file tree
Showing 4 changed files with 127 additions and 42 deletions.
73 changes: 73 additions & 0 deletions .github/workflows/deposits_data_cronjob.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
name: Update deposits data

on:
schedule:
# https://crontab.guru/#0_9_*_*_*
# Every day at 9am UTC
- cron: "0 9 * * *"

jobs:
deploy:
name: Deployment
runs-on: ubuntu-latest

steps:
# Ref: https://github.com/actions/checkout/issues/1471#issuecomment-1771231294
- uses: actions/checkout@v4

- name: Get latest tag available
id: latest_tag
run: echo "tag=$(git ls-remote --tags --sort=committerdate | grep -o 'v.*' | sort -r | head -1)" >> "$GITHUB_OUTPUT"

- name: Tag checkout
run: |
git fetch --prune --unshallow --tags
git checkout ${{ steps.latest_tag.outputs.tag }}
- uses: actions/cache@v2
with:
path: '**/node_modules'
key: ${{ runner.os }}-modules-${{ hashFiles('**/yarn.lock') }}

- name: Setup Node.js
uses: actions/setup-node@v2

- name: Install
run: |
rm -rf .cache
rm -rf build
yarn config set cache-folder .yarn
yarn install
pip install awscli --upgrade --user
- name: Build deposits map
run: yarn update-deposits

- name: Configure AWS Production credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.PROD_AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.PROD_AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.PROD_AWS_DEFAULT_REGION }}

# Script to deploy to release environment
- name: 'Deploy to S3: Release'
run: |
aws s3 sync data s3://${{ secrets.RELEASE_BUCKET_NAME }}/data --delete
- name: 'Cloudfront: cache invalidation'
run: |
aws cloudfront create-invalidation --distribution-id ${{ secrets.PROD_AWS_CLOUDFRONT_ID }} --paths "/data/*"
notify:
uses: ./.github/workflows/slack_release_notification.yml
if: ${{ always() }}
needs: [ deploy ]
secrets:
RELEASES_SLACK_WEBHOOK_URL: ${{ secrets.RELEASES_SLACK_WEBHOOK_URL }}
with:
environment: Production
service: GC Deposit UI - Update Deposits
success: ${{ contains(join(needs.*.result, ','), 'success') }}
message: "deploy service `GC Deposit UI - Update Deposits data` version `${{ inputs.tag }}`. Triggered by `${{ github.actor }}`."

Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,18 @@ jobs:
- name: 'Deploy to S3: Development'
if: github.ref == 'refs/heads/dev'
run: |
aws s3 sync build/ s3://${{ secrets.DEV_BUCKET_NAME }}/dev --exclude "*.html" --cache-control max-age=0,no-cache,no-store,public
aws s3 sync build/ s3://${{ secrets.DEV_BUCKET_NAME }}/dev --exclude "*" --include "*.html" --cache-control max-age=0,no-cache,no-store,must-revalidate --content-type text/html
aws s3 sync build/ s3://${{ secrets.DEV_BUCKET_NAME }}/dev --exclude "*.html" --cache-control max-age=0,no-cache,no-store,public --delete
aws s3 sync build/ s3://${{ secrets.DEV_BUCKET_NAME }}/dev --exclude "*" --include "*.html" --cache-control max-age=0,no-cache,no-store,must-revalidate --content-type text/html --delete
aws s3 sync data s3://${{ secrets.DEV_BUCKET_NAME }}/dev/data --delete
# Script to deploy to staging environment
- name: 'Deploy to S3: Staging'
if: github.ref == 'refs/heads/main'
run: |
aws s3 sync build/ s3://${{ secrets.DEV_BUCKET_NAME }}/main --exclude "*.html" --cache-control max-age=0,no-cache,no-store,public
aws s3 sync build/ s3://${{ secrets.DEV_BUCKET_NAME }}/main --exclude "*" --include "*.html" --cache-control max-age=0,no-cache,no-store,must-revalidate --content-type text/html
aws s3 sync data s3://${{ secrets.DEV_BUCKET_NAME }}/main/data --delete
aws s3 sync build/ s3://${{ secrets.DEV_BUCKET_NAME }}/main --exclude "*.html" --cache-control max-age=0,no-cache,no-store,public --delete
aws s3 sync build/ s3://${{ secrets.DEV_BUCKET_NAME }}/main --exclude "*" --include "*.html" --cache-control max-age=0,no-cache,no-store,must-revalidate --content-type text/html --delete
aws s3 sync data s3://${{ secrets.DEV_BUCKET_NAME }}/main/data --delete
- name: 'Cloudfront: cache invalidation'
run: |
aws cloudfront create-invalidation --distribution-id ${{ secrets.DEV_AWS_CLOUDFRONT_ID }} --paths "/*"
4 changes: 4 additions & 0 deletions .github/workflows/prod_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ jobs:
aws s3 sync build/ s3://${{ secrets.RELEASE_BUCKET_NAME }} --delete --exclude "*" --include "sitemap.xml" --cache-control max-age=0,no-cache,no-store,must-revalidate --content-type text/xml
aws s3 sync data s3://${{ secrets.RELEASE_BUCKET_NAME }}/data --delete
- name: 'Cloudfront: cache invalidation'
run: |
aws cloudfront create-invalidation --distribution-id ${{ secrets.PROD_AWS_CLOUDFRONT_ID }} --paths "/*"
notify:
uses: ./.github/workflows/slack_release_notification.yml
if: ${{ always() }}
Expand Down
78 changes: 41 additions & 37 deletions components/validator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,44 +13,48 @@ export default function Validator() {
const [errorMessage, setErrorMessage] = useState("");
const [loading, setLoading] = useState(false);
const [step, setStep] = useState("validation");
const onDrop = useCallback(async (acceptedFiles: File[], rejectedFiles: FileRejection[]) => {
if (rejectedFiles.length > 0) {
setErrorMessage("Please upload a valid JSON file.");
} else if (acceptedFiles.length > 0) {
const data = await Promise.all(
acceptedFiles.map(
(file) =>
new Promise<FileDepositData>((resolve) => {
const reader = new FileReader();
reader.onload = async (event) => {
if (event.target?.result) {
const depositData = JSON.parse(event.target.result as string);
resolve({
fileName: file.name,
data: depositData,
});
}
};
reader.readAsText(file);
})
)
);
try {
setLoading(true);
await validateStatus(data);
setStep("validated");
setLoading(false);
} catch (error: unknown) {
console.log(error);
setLoading(false);
if (error instanceof Error) {
setErrorMessage(error.message);
} else {
setErrorMessage("An unexpected error occurred.");

const onDrop = useCallback(
async (acceptedFiles: File[], rejectedFiles: FileRejection[]) => {
if (rejectedFiles.length > 0) {
setErrorMessage("Please upload a valid JSON file.");
} else if (acceptedFiles.length > 0) {
const data = await Promise.all(
acceptedFiles.map(
(file) =>
new Promise<FileDepositData>((resolve) => {
const reader = new FileReader();
reader.onload = async (event) => {
if (event.target?.result) {
const depositData = JSON.parse(event.target.result as string);
resolve({
fileName: file.name,
data: depositData,
});
}
};
reader.readAsText(file);
})
)
);
try {
setLoading(true);
await validateStatus(data);
setStep("validated");
setLoading(false);
} catch (error: unknown) {
console.log(error);
setLoading(false);
if (error instanceof Error) {
setErrorMessage(error.message);
} else {
setErrorMessage("An unexpected error occurred.");
}
}
}
}
}, [validateStatus]);
},
[validateStatus]
);
const { getRootProps, getInputProps } = useDropzone({ onDrop, accept: { "application/json": [] } });

return (
Expand All @@ -72,7 +76,7 @@ export default function Validator() {
{errorMessage && <p className="text-red-400 text-sm">{errorMessage.substring(0, 150)}</p>}
</div>
) : step === "validated" ? (
<div className="w-full flex flex-col items-center">
<div className="w-full h-full flex flex-col items-center">
{statuses && statuses.length > 0 ? (
<div className="overflow-y-auto">
{statuses.map((status, index) => (
Expand Down

0 comments on commit 3fa62c1

Please sign in to comment.