Merge Staging to Master #1508
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Merge Staging to Master | |
on: | |
workflow_dispatch: | |
schedule: | |
- cron: "0 */2 * * *" | |
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`); | |
} | |
} | |
call-resize-images-workflow: | |
needs: create-pull-request | |
if: ${{ needs.create-pull-request.outputs.pr_number != 'NA' }} | |
uses: TitleCardMaker/Blueprints/.github/workflows/resize_images.yml@master | |
secrets: inherit | |
call-update-database-workflow: | |
needs: [call-resize-images-workflow] | |
if: ${{ needs.create-pull-request.outputs.pr_number != 'NA' }} | |
uses: TitleCardMaker/Blueprints/.github/workflows/update_database.yml@master | |
secrets: inherit | |
call-pytest-workflow: | |
needs: [call-update-database-workflow] | |
if: ${{ needs.create-pull-request.outputs.pr_number != 'NA' }} | |
uses: TitleCardMaker/Blueprints/.github/workflows/pytest.yml@master | |
notify-discord: | |
needs: [call-pytest-workflow] | |
if: ${{ needs.create-pull-request.outputs.pr_number != 'NA' }} | |
runs-on: ubuntu-latest | |
steps: | |
# 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 }} | |
# Check out repository | |
- name: Checkout Repository | |
uses: actions/checkout@v3 | |
with: | |
ref: refs/heads/staging | |
persist-credentials: false | |
fetch-depth: 0 | |
# Run script to parse issue | |
- 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: 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] | |
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 }} |