From deaebeb2adc2d48438fa70eb7fe44ba38011a6d4 Mon Sep 17 00:00:00 2001 From: Timur Moziev Date: Thu, 16 Jan 2025 13:48:16 +0300 Subject: [PATCH] add cinnabar-meta actions --- .github/workflows/cinnabar-meta-master.yml | 105 ++++++++++++++++++ .../workflows/cinnabar-meta-pull-requests.yml | 23 ++++ 2 files changed, 128 insertions(+) create mode 100644 .github/workflows/cinnabar-meta-master.yml create mode 100644 .github/workflows/cinnabar-meta-pull-requests.yml diff --git a/.github/workflows/cinnabar-meta-master.yml b/.github/workflows/cinnabar-meta-master.yml new file mode 100644 index 0000000..1b89a26 --- /dev/null +++ b/.github/workflows/cinnabar-meta-master.yml @@ -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 }} diff --git a/.github/workflows/cinnabar-meta-pull-requests.yml b/.github/workflows/cinnabar-meta-pull-requests.yml new file mode 100644 index 0000000..416859c --- /dev/null +++ b/.github/workflows/cinnabar-meta-pull-requests.yml @@ -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