Skip to content

Commit

Permalink
feat(auto-pr): update setup-node for auto create assets-pr
Browse files Browse the repository at this point in the history
  • Loading branch information
49659410+tx0c committed Apr 24, 2024
1 parent 530f8d9 commit a8cfee1
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 12 deletions.
32 changes: 24 additions & 8 deletions .github/workflows/checkin-assets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Billboard Rounds - Create PR to update latest round
on: workflow_dispatch

jobs:
create-pull-request:
ci-round-assets:
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
Expand All @@ -12,21 +12,37 @@ jobs:
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
node-version: '>=20'

- name: Install Dependencies
run: npm install @aws-sdk/client-s3 ## the only dependency for ./bin/sync-up-latest-round.mjs

- run: ./bin/sync-up-latest-round.mjs
- name: Sync up Latest Round
run: "./bin/sync-up-latest-round.mjs | tee message.log"
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_REGION: ap-southeast-1

- uses: gr2m/create-or-update-pull-request-action@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Create Pull Request
id: cpr
uses: peter-evans/create-pull-request@v6
with:
path: "./public/static"
## token: ${{ secrets.BILLBOARD_GITHUB_TOKEN }}
commit-message: auto checkin latest Round assets as Preview
base: main
signoff: false
branch: auto/round-assets
delete-branch: true
# path: public/static
add-paths: public/static
title: check in latest round Assets
body-path: message.log
body: |
Update preview Assets
- Updated with *today's* date
- Auto-generated by [create-pull-request][1]
[1]: https://github.com/peter-evans/create-pull-request
labels: assets, automated pr
draft: true
13 changes: 9 additions & 4 deletions bin/sync-up-latest-round.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,19 @@ const client = new S3Client() // use credentials from environment

const AssetsDir = './public/static'

export const main = async () => {
export const main = async (branch = 'prod') => {
const controller = new AbortController()
const { signal } = controller
const developPrefix = branch !== 'prod' ? 'web-develop/' : ''

console.log('```console')
try {
// The Body object also has 'transformToByteArray' and 'transformToWebStream' methods.
const roundsContent = await (
await client.send(
new GetObjectCommand({
Bucket: 'matters-billboard',
Key: 'rounds/rounds.json',
Key: `${developPrefix}rounds/rounds.json`,
})
)
).Body.transformToString()
Expand Down Expand Up @@ -47,7 +49,7 @@ export const main = async () => {
await client.send(
new GetObjectCommand({
Bucket: 'matters-billboard',
Key: `rounds/${lastRound.dirpath}/${file}`,
Key: `${developPrefix}rounds/${lastRound.dirpath}/${file}`,
})
)
).Body.transformToString()
Expand All @@ -66,6 +68,9 @@ export const main = async () => {
} catch (err) {
console.error(new Date(), `ERROR:`, err)
}

console.log('```')
}

await main()
// console.log('run with argv:', process.argv)
await main(process.argv?.[2] || 'prod')

0 comments on commit a8cfee1

Please sign in to comment.