Skip to content

Merge Staging to Master #4098

Merge Staging to Master

Merge Staging to Master #4098

name: Merge Staging to Master
on:
workflow_dispatch:
schedule:
- cron: "0 */4 * * *"
jobs:
create-pull-request:
runs-on: ubuntu-latest
outputs:
pr_number: ${{ steps.create_pr.outputs.pr_number }}
steps:
# Check out the repository
- name: Checkout Repository
uses: actions/checkout@v4
# Get list of open issues that are labeled as "created"
- name: Get Open Issues
id: get_issues
uses: octokit/[email protected]
with:
route: GET /repos/${{ github.repository }}/issues?labels=created,passed-tests&state=open
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Create a Pull Request to merge staging -> master
- name: Create Pull Request
id: create_pr
uses: actions/github-script@v7
with:
script: |
const { repo, owner } = context.repo;
const issuesList = JSON.parse(${{ toJSON(steps.get_issues.outputs.data) }}).map(issue => `- Closes #${issue.number}`).join("\n");
try {
const result = await github.rest.pulls.create({
title: `[Auto] Merge Staging to Master [${(new Date()).toLocaleDateString()}]`,
owner,
repo,
head: 'staging',
base: 'master',
body: `This is an automated pull request.\n\nList of issues to be closed:\n${issuesList}`,
});
// Store the pull request number in the 'pr_number' output variable
console.log(`::set-output name=pr_number::${result.data.number}`);
} catch (error) {
if (error.message.includes('No commits between')) {
console.log(`::set-output name=pr_number::NA`);
}
}
update-artifacts-and-notify-discord:
needs: create-pull-request
if: ${{ needs.create-pull-request.outputs.pr_number != 'NA' }}
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
with:
ref: refs/heads/staging
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
cache: 'pip'
- name: Install dependencies
run: |
python -m pip install -r requirements.txt
- name: (Python) Resize Images
run: |
python entrypoint.py --resize-images
- name: (Python) Lint Blueprints, Update Database, Build Readmes
run: |
python entrypoint.py --lint-blueprints --update-database --build-readme
- name: (Python) Run pytest
run: |
pytest ./src/tests/
- name: Commit Updated Files
run: |
git config pull.rebase false
git config --local user.email "[email protected]"
git config --local user.name "TitleCardMakerBot"
git add .
git diff-index --quiet HEAD || git commit -a -m "Resize Preview Images, Update Database and README Files"
git pull
- run: git pull
- name: Push changes
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: refs/heads/staging
# Get list of open issues that are labeled as "created"
- name: Get Open Issues
id: get_issues
uses: octokit/[email protected]
with:
route: GET /repos/${{ github.repository }}/issues?labels=created,passed-tests,blueprint&state=open
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: (Python) Send Discord Message
env:
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }}
DISCORD_AVATAR: https://raw.githubusercontent.com/CollinHeist/static/main/logo.png
ISSUES: ${{ steps.get_issues.outputs.data }}
run: |
python entrypoint.py --notify-discord
merge-pull-request:
# needs: [create-pull-request, call-resize-images-workflow, call-update-database-workflow, call-pytest-workflow, notify-discord]
needs: [create-pull-request, update-artifacts-and-notify-discord]
if: ${{ needs.create-pull-request.outputs.pr_number != 'NA' }}
runs-on: ubuntu-latest
steps:
- name: Merge Pull Request
uses: octokit/[email protected]
with:
route: PUT /repos/${{ github.repository }}/pulls/${{ needs.create-pull-request.outputs.pr_number }}/merge
token: ${{ secrets.GITHUB_TOKEN }}