From 0a7584cd6bfdd0620ffe37cd615fb4fbd37dbc7f Mon Sep 17 00:00:00 2001 From: alecdwm Date: Mon, 2 Oct 2023 05:30:37 +0000 Subject: [PATCH] added fetch-external workflow --- .github/workflows/fetch-external.yml | 45 ++++++++++++++++++++ .github/workflows/publish.yml | 4 +- package.json | 1 + scripts/fetch-external.ts | 12 ++++++ scripts/fetch-external/steps/doSomeThings.ts | 17 ++++++++ 5 files changed, 77 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/fetch-external.yml create mode 100644 scripts/fetch-external.ts create mode 100644 scripts/fetch-external/steps/doSomeThings.ts diff --git a/.github/workflows/fetch-external.yml b/.github/workflows/fetch-external.yml new file mode 100644 index 0000000000..372574b582 --- /dev/null +++ b/.github/workflows/fetch-external.yml @@ -0,0 +1,45 @@ +name: Chaindata Fetch External + +on: + # runs at `0 minutes past the hour, every 6 hours`, starting at midnight UTC + schedule: + - cron: '0 0/6 * * *' + # can be run manually from the `Actions` tab + workflow_dispatch: + +# Sets permissions of the GITHUB_TOKEN to allow pushing commits +permissions: + contents: write + id-token: write + +concurrency: + # only run 1 job per branch/pr/etc at a time + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: ${{ github.event_name == 'pull_request' }} + +jobs: + publish: + name: 'Fetch externals and push changes to repo' + timeout-minutes: 15 + runs-on: ubuntu-latest + + steps: + - name: Checkout repo + uses: actions/checkout@v3 + - name: Setup pnpm + uses: pnpm/action-setup@v2 + - name: Setup Node + uses: actions/setup-node@v3 + with: + node-version-file: 'package.json' + cache: pnpm + - name: Install dependencies + run: pnpm install --frozen-lockfile + - name: Fetch external + run: pnpm fetch-external + - name: Commit changes + run: | + git config user.name github-actions + git config user.email github-actions@github.com + git commit -am 'updated externals' + git push diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index bdcfd3bfed..79a013f532 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -4,9 +4,9 @@ on: # runs on each commit pushed to the `main` branch push: branches: [main] - # runs at `0 minutes past the hour, every 6 hours`, starting at midnight UTC + # runs at `30 minutes past the hour, every 6 hours`, starting at midnight UTC schedule: - - cron: '0 0/6 * * *' + - cron: '30 0/6 * * *' # can be run manually from the `Actions` tab workflow_dispatch: diff --git a/package.json b/package.json index a2ac297795..9d1709411b 100644 --- a/package.json +++ b/package.json @@ -26,6 +26,7 @@ "import-pjs-config": "node scripts/import-pjs-config.js", "update": "pnpm run update-pjs && pnpm run import-pjs-config", "typecheck": "tsc --noEmit", + "fetch-external": "tsx scripts/fetch-external.ts", "build": "tsx scripts/build.ts", "clean": "rm -rf dist" }, diff --git a/scripts/fetch-external.ts b/scripts/fetch-external.ts new file mode 100644 index 0000000000..54822dbdbf --- /dev/null +++ b/scripts/fetch-external.ts @@ -0,0 +1,12 @@ +import startCase from 'lodash/startCase' + +import { doSomeThings } from './fetch-external/steps/doSomeThings' + +const steps: Array<() => Promise> = [doSomeThings] + +for (const [index, executeStep] of steps.entries()) { + console.log(`Executing step ${index + 1}: ${startCase(executeStep.name)}`) + await executeStep() +} + +process.exit(0) diff --git a/scripts/fetch-external/steps/doSomeThings.ts b/scripts/fetch-external/steps/doSomeThings.ts new file mode 100644 index 0000000000..086b9da792 --- /dev/null +++ b/scripts/fetch-external/steps/doSomeThings.ts @@ -0,0 +1,17 @@ +import { writeFile } from 'node:fs/promises' + +export const doSomeThings = async () => { + await writeFile( + 'assets/test-pls-delete.svg', + ` + + + + ` + ) +}