Skip to content

Commit

Permalink
add cinnabar-meta actions
Browse files Browse the repository at this point in the history
  • Loading branch information
TimurRin committed Jan 16, 2025
1 parent ea8ebe8 commit deaebeb
Show file tree
Hide file tree
Showing 2 changed files with 128 additions and 0 deletions.
105 changes: 105 additions & 0 deletions .github/workflows/cinnabar-meta-master.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
name: Cinnabar Meta Version Updater
on:
push:
branches:
- master

permissions:
pull-requests: read

jobs:
run-cinnabar-meta:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
token: ${{ secrets.CINNABAR_META_PAT }}
fetch-depth: 0
fetch-tags: true
submodules: recursive

- name: Check if update.cinnabarmeta exists
id: check-file
run: |
if [ -f "update.cinnabarmeta" ]; then
echo "::set-output name=file_exists::true"
else
echo "::set-output name=file_exists::false"
fi
- name: Exit if update.cinnabarmeta does not exist
if: steps.check-file.outputs.file_exists == 'false'
run: exit 0

- name: Collect pull requests
if: steps.check-file.outputs.file_exists == 'true'
id: collect-prs
uses: actions/github-script@v6
with:
script: |
const { execSync } = require('child_process');
const latestTag = execSync('git tag --sort=-creatordate | head -n 1').toString().trim();
console.log(`Latest tag: ${latestTag}`);
const tagCommitDate = execSync(`git log -1 --format=%ai ${latestTag}`).toString().trim();
console.log(`Latest tag commit date: ${tagCommitDate}`);
const { data: pulls } = await github.rest.pulls.list({
owner: context.repo.owner,
repo: context.repo.repo,
state: 'closed',
base: 'master',
sort: 'updated',
direction: 'desc',
});
const filteredPRs = pulls.filter(pr => {
return pr.merged_at && new Date(pr.merged_at) > new Date(tagCommitDate);
});
const prList = filteredPRs.map(pr => `- ${pr.title} (#${pr.number})`).join('\n');
const fs = require('fs');
fs.writeFileSync('.cinnabar-meta-pull-requests.md', prList);
console.log(`Collected PRs:\n${prList}`);
- name: Install Cinnabar Meta
if: steps.check-file.outputs.file_exists == 'true'
run: npm i -g @cinnabar-forge/meta

- name: Set up Git user
if: steps.check-file.outputs.file_exists == 'true'
run: |
git config --global user.name ${{ vars.TECHNICAL_USER_NAME }}
git config --global user.email ${{ vars.TECHNICAL_USER_EMAIL }}
- name: Run cinnabar-meta command
if: steps.check-file.outputs.file_exists == 'true'
run: cinnabar-meta --file

- name: Push changes and tags
if: steps.check-file.outputs.file_exists == 'true'
run: |
git push origin --atomic HEAD:master --tags
- name: Read version from ./tmp/version
id: read-version
if: steps.check-file.outputs.file_exists == 'true'
run: |
VERSION=$(cat ./tmp/version)
echo "::set-output name=version::$VERSION"
- name: Create release
if: steps.check-file.outputs.file_exists == 'true'
uses: actions/create-release@v1
with:
tag_name: v${{ steps.read-version.outputs.version }}
release_name: v${{ steps.read-version.outputs.version }}
body_path: ./tmp/CHANGELOG-latest.md
draft: false
prerelease: false
env:
GITHUB_TOKEN: ${{ secrets.CINNABAR_META_PAT }}
23 changes: 23 additions & 0 deletions .github/workflows/cinnabar-meta-pull-requests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Cinnabar Meta Pull Request Check
on:
pull_request:
types: [opened, synchronize]

jobs:
check-file-exists:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
ref: ${{ github.head_ref }}

- name: Check if update.cinnabarmeta exists
id: check-file
run: |
if [ -f "update.cinnabarmeta" ]; then
echo "File exists, proceeding..."
else
echo "File does not exist, failing the action..."
exit 1
fi

0 comments on commit deaebeb

Please sign in to comment.