forked from tinymanorg/asa-list
-
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.
Add scripts and GH workflow to upload icons to S3
- Loading branch information
Showing
4 changed files
with
146 additions
and
0 deletions.
There are no files selected for viewing
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,38 @@ | ||
name: upload-to-s3 | ||
|
||
on: | ||
push: | ||
branches: | ||
- feat/gh-action-to-upload-to-s3 | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Setup repo | ||
uses: actions/checkout@v2 | ||
with: | ||
persist-credentials: false | ||
|
||
- name: Setup Node.js | ||
uses: actions/setup-node@v1 | ||
with: | ||
node-version: 14.17.0 | ||
|
||
- name: Configure AWS Credentials | ||
uses: aws-actions/configure-aws-credentials@v1 | ||
with: | ||
# TestNet S3 credentials are the same with Staging | ||
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | ||
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | ||
aws-region: eu-central-1 | ||
|
||
- name: Prepare build folder | ||
run: node build.mjs | ||
|
||
- name: Upload to S3 bucket | ||
run: aws s3 sync ./build/ s3://asa-list --delete --acl=public-read | ||
|
||
- name: Remove build folder | ||
run: node cleanup.mjs |
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,90 @@ | ||
import path from "path"; | ||
import { readdir, mkdir } from "fs/promises"; | ||
import { | ||
existsSync, | ||
mkdirSync, | ||
lstatSync, | ||
readdirSync, | ||
copyFileSync, | ||
} from "fs"; | ||
import { buildDirectory, currentDirname } from "./constants.mjs"; | ||
|
||
const ASSET_ID_MATCHER = /\d+/; | ||
|
||
try { | ||
await mkdir(buildDirectory); | ||
const files = await readdir(currentDirname); | ||
|
||
for (const file of files) { | ||
try { | ||
const folderFiles = await readdir(path.join(currentDirname, file)); | ||
|
||
if (folderFiles.some((folderFile) => folderFile.includes("icon.png"))) { | ||
copyDirectorySync(file, buildDirectory); | ||
} | ||
} catch (error) { | ||
// not a directory | ||
} | ||
} | ||
} catch (err) { | ||
console.error(err); | ||
} | ||
|
||
/** | ||
* @param {string} source | ||
* @returns Directory name that includes only asset ids | ||
*/ | ||
function createTargetDirectoryName(source) { | ||
let sourceDirName = source; | ||
|
||
if (sourceDirName.match(ASSET_ID_MATCHER)) { | ||
sourceDirName = sourceDirName.match(ASSET_ID_MATCHER)[0]; | ||
} else { | ||
// it is ALGO folder | ||
sourceDirName = "0"; | ||
} | ||
|
||
return sourceDirName; | ||
} | ||
|
||
function copyDirectorySync(source, target) { | ||
let targetDirName = createTargetDirectoryName(path.basename(source)); | ||
var files = []; | ||
|
||
// Check if folder needs to be created or integrated | ||
var targetFolder = path.join(target, targetDirName); | ||
|
||
if (!existsSync(targetFolder)) { | ||
console.log(`┏━━━ Creating ${targetFolder} ━━━━━━━━━━━━`); | ||
mkdirSync(targetFolder); | ||
} | ||
|
||
// Copy source | ||
if (lstatSync(source).isDirectory()) { | ||
console.log( | ||
` | ||
Copying contents of ${source} into ${targetFolder} ━━━━━━━━━━━━` | ||
); | ||
|
||
files = readdirSync(source); | ||
files.forEach(function (file) { | ||
var curSource = path.join(source, file); | ||
|
||
if (lstatSync(curSource).isDirectory()) { | ||
copyDirectorySync(curSource, targetFolder); | ||
} else { | ||
console.log(`••••• Copying ${curSource}`); | ||
|
||
copyFileSync(curSource, path.join(targetFolder, file)); | ||
} | ||
}); | ||
|
||
console.log(` | ||
━━━━━━━━━━━━ Finished copying ${source} ━━━━━━━━━━━━ | ||
`); | ||
} | ||
} |
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,8 @@ | ||
import { rm } from "fs/promises"; | ||
import { buildDirectory } from "./constants.mjs"; | ||
|
||
try { | ||
rm(buildDirectory, { recursive: true }); | ||
} catch (error) { | ||
console.error(error); | ||
} |
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,10 @@ | ||
import { fileURLToPath } from "url"; | ||
import path from "path"; | ||
|
||
const __filename = fileURLToPath(import.meta.url); | ||
|
||
const currentDirname = path.dirname(__filename); | ||
|
||
const buildDirectory = path.join(currentDirname, "build"); | ||
|
||
export { currentDirname, buildDirectory }; |