Skip to content

ci-automated-check-environment #272

ci-automated-check-environment

ci-automated-check-environment #272

# This checks whether there are new CI environment versions available, e.g. MongoDB, Node.js;
# a pull request is created if there are any available.
name: ci-automated-check-environment
on:
schedule:
- cron: 0 0 1/7 * *
workflow_dispatch:
jobs:
check-ci-environment:
timeout-minutes: 5
runs-on: ubuntu-latest
steps:
- name: Checkout default branch
uses: actions/checkout@v4
- name: Setup Node
uses: actions/setup-node@v2
with:
node-version: 20
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: CI Environments Check
run: npm run ci:check
create-pr:
needs: check-ci-environment
if: failure()
timeout-minutes: 5
runs-on: ubuntu-latest
steps:
- name: Checkout default branch
uses: actions/checkout@v4
- name: Compose branch name for PR
id: branch
run: echo "::set-output name=name::ci-bump-environment"
- name: Create branch
run: |
git config --global user.email ${{ github.actor }}@users.noreply.github.com
git config --global user.name ${{ github.actor }}
git checkout -b ${{ steps.branch.outputs.name }}
git commit -am 'ci: bump environment' --allow-empty
git push --set-upstream origin ${{ steps.branch.outputs.name }}
- name: Create or update PR
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const owner = context.repo.owner;
const repo = context.repo.repo;
const head = '${{ steps.branch.outputs.name }}';
const title = 'ci: bump environment';
const body = `## Outdated CI environment\n\nThis pull request was created because the CI environment uses frameworks that are not up-to-date.\nYou can see which frameworks need to be upgraded in the [logs](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}).\n\n*⚠️ Use \`Squash and merge\` to merge this pull request.*`;
// Check for existing open PR
const pulls = await github.rest.pulls.list({
owner,
repo,
head: `${owner}:${head}`,
state: 'open',
});
if (pulls.data.length > 0) {
const prNumber = pulls.data[0].number;
await github.rest.pulls.update({
owner,
repo,
pull_number: prNumber,
title,
body,
});
core.info(`Updated PR #${prNumber}`);
} else {
const pr = await github.rest.pulls.create({
owner,
repo,
title,
body,
head,
base: (await github.rest.repos.get({ owner, repo })).data.default_branch,
});
core.info(`Created PR #${pr.data.number}`);
}