Skip to content

Update Rete CLI in repositories #6

Update Rete CLI in repositories

Update Rete CLI in repositories #6

name: Update Rete CLI in repositories
on:
workflow_dispatch:
inputs:
version:
description: 'Rete CLI version'
required: true
default: 'latest'
commit-message:
description: 'Commit message'
required: true
default: 'build: update Rete CLI'
jobs:
get-repositories:
runs-on: ubuntu-latest
outputs:
list: ${{ steps.repos.outputs.result }}
steps:
- uses: actions/github-script@v7
id: repos
with:
script: |
async function getCustomProperties(owner, repo) {
const customProperties = await github.request('GET /repos/{owner}/{repo}/properties/values', {
owner: owner,
repo: repo,
headers: {
'X-GitHub-Api-Version': '2022-11-28'
}
})
return Object.fromEntries(customProperties.data.map(item => [item.property_name, item.value]))
}
const response = await github.rest.repos.listForOrg({
org: "retejs",
per_page: 100
})
const repos = await Promise.all(response.data.map(repo => repo.name).map(async repo => {
return {
name: repo,
properties: await getCustomProperties('retejs', repo)
}
}))
return repos.filter(repo => repo.properties['npm-package'] === 'true').map(repo => repo.name)
- name: Found repositories
run: |
echo ${{steps.repos.outputs.result}}
update-repositories:
needs: get-repositories
if: success('get-repositories')
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
repository: [rete-cli] # ${{fromJson(needs.get-repositories.outputs.list)}}
steps:
- name: Enter the repository
run: echo ${{ matrix.repository }}
- name: Generate token
id: generate_token
uses: tibdex/github-app-token@v1
with:
app_id: ${{ secrets.APP_ID }}
private_key: ${{ secrets.APP_PRIVATE_KEY }}
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 0
token: ${{ steps.generate_token.outputs.token }}
repository: retejs/${{ matrix.repository }}
- uses: actions/setup-node@v4
with:
node-version: 20
- name: Check if Rete CLI is needed to update
id: check
uses: actions/github-script@v7
with:
script: |
const pkg = require('./package.json')
const deps = [
...Object.keys(pkg.dependencies || {}),
...Object.keys(pkg.devDependencies || {})
]
return deps.includes('rete-cli')
- name: Update Rete CLI
if: steps.check.outputs.result == 'true'
run: |
npm i rete-cli@${{ inputs.version }}
- name: Create Pull Request
if: steps.check.outputs.result == 'true'
uses: peter-evans/create-pull-request@v5
with:
token: ${{ steps.generate_token.outputs.token }}
author: rete-js[bot] <rete-js[bot]@users.noreply.github.com>
commit-message: ${{ inputs.commit-message }}
title: Update Rete CLI
branch: update-rete-cli
body: "Bulk Rete CLI update"
reviewers: Ni55aN