This repository has been archived by the owner on Oct 24, 2024. It is now read-only.
Added Jade config strings #24
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
# Triggered by "/fast-forward" comment in PR. | |
# Copied from https://github.com/khanshoaib3/stardew-access/blob/development/.github/workflows/fast-forward.yml | |
name: Fast-forward and Auto Merge and Generate Translation Files | |
on: | |
issue_comment: | |
types: [ created, edited ] | |
jobs: | |
auto: | |
permissions: | |
issues: write | |
pull-requests: write | |
contents: write | |
name: Sort, Merge, Generate, Commit | |
runs-on: ubuntu-latest | |
# Only run the job if:- | |
# 1. It is a pull request | |
# 2. It's not closed | |
# 3. The comment was by the owner or one of the collaborator | |
# 4. The comment message is "/fast-forward" | |
if: | | |
github.event.issue.pull_request && | |
!github.event.issue.closed_at && | |
github.event.issue.state == 'open' && | |
(github.event.comment.author_association == 'OWNER' || github.event.comment.author_association == 'COLLABORATOR') && | |
contains(github.event.comment.body, '/fast-forward') | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
# API: https://docs.github.com/en/rest/pulls/pulls?apiVersion=2022-11-28#get-a-pull-request | |
- name: Get PR details | |
uses: octokit/[email protected] | |
id: get-pr-details | |
with: | |
route: GET /repos/{repository}/pulls/{pull_number} | |
repository: ${{ github.repository }} | |
pull_number: ${{ github.event.issue.number }} | |
env: | |
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }} | |
- name: Set environment variables | |
run: | | |
MERGE_STATUS=${{ fromJson(steps.get-pr-details.outputs.data).mergeable }} | |
if $MERGE_STATUS; then echo "COMMENT=\[Fast Forward CI\] ${{ env.HEAD_REF }} cannot be merged into ${{ env.BASE_REF }} at the moment." >> $GITHUB_ENV; fi | |
echo "MERGE_STATUS=$MERGE_STATUS" >> $GITHUB_ENV | |
echo "BASE_REF=${{ fromJson(steps.get-pr-details.outputs.data).base.ref }}" >> $GITHUB_ENV | |
echo "HEAD_REF=${{ fromJson(steps.get-pr-details.outputs.data).head.ref }}" >> $GITHUB_ENV | |
# Merges the head branch into base branch | |
# Only runs if the merge status is "clean", clean might refer to when the merge button is green in the PR's page, there's no clear indication of it's values in docs | |
# For forks the following script adds the fork as a remote, them merges it into base | |
- name: Merge the head branch into base in a fast forward manner only | |
if: ${{ env.MERGE_STATUS }} | |
run: | | |
git config --global user.email "[email protected]" | |
git config --global user.name "GitHub Action" | |
git checkout ${{ env.BASE_REF }} | |
git pull origin ${{ env.BASE_REF }} | |
if ${{ fromJson(steps.get-pr-details.outputs.data).head.repo.fork }}; then | |
USER_NAME=${{ fromJson(steps.get-pr-details.outputs.data).head.user.login }} | |
git remote add $USER_NAME ${{ fromJson(steps.get-pr-details.outputs.data).head.repo.clone_url }} | |
git pull $USER_NAME ${{ env.HEAD_REF }} | |
git merge --ff-only $USER_NAME/${{ env.HEAD_REF }} | |
else | |
git pull origin ${{ env.HEAD_REF }} | |
git merge --ff-only origin/${{ env.HEAD_REF }} | |
fi | |
echo "COMMENT=\[Fast Forward CI\] ${{ env.HEAD_REF }} merged into ${{ env.BASE_REF }}..." >> $GITHUB_ENV | |
- name: Check Changed Files | |
uses: dorny/paths-filter@v3 | |
id: changes | |
with: | |
filters: | | |
trans: | |
- "*.json" | |
- ".ci/new_translation/*" | |
# Run only if translation files are changed | |
# | |
# The tool.sh uses jq to format json files, | |
# the jq tool is pre-installed in GitHub Action Servers. | |
# ref: https://github.com/actions/runner-images/blob/main/images/ubuntu/Ubuntu2204-Readme.md#tools | |
# | |
# By the way, the Action Servers also have Python 3.10.2 installed, | |
# so next time (if there will be) I'll use Python instead of | |
# coding while learning shell script and command line tools... | |
- name: Auto Merge and Generate Translation Files | |
if: steps.changes.outputs.trans == 'true' | |
run: | | |
cd .ci | |
bash tool.sh | |
cd .. | |
# If (git diff-index --quiet HEAD) is 0, it means there is no change | |
# ref: https://stackoverflow.com/a/3899339/11397457 | |
# set +e: disable the "exit on failure" | |
- name: Commit Changes | |
if: steps.changes.outputs.trans == 'true' | |
run: | | |
set +e | |
git add . | |
git diff-index --quiet HEAD | |
if [ $? -ne 0 ]; then | |
git commit -m "chore: auto merge and generate translation files" | |
fi | |
- name: Push to origin | |
if: ${{ env.MERGE_STATUS }} | |
run: | | |
git push origin | |
echo "COMMENT=${{ env.COMMENT }} Pushed the changes to origin." >> $GITHUB_ENV | |
# Post a success/failure comment to the PR. | |
- name: Add success/failure comment to PR | |
uses: octokit/[email protected] | |
with: | |
route: POST /repos/{repository}/issues/{issue_number}/comments | |
repository: ${{ github.repository }} | |
issue_number: ${{ github.event.issue.number }} | |
body: ${{ env.COMMENT }} | |
env: | |
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }} | |
# Post a failure message when any of the previous steps fail. | |
- name: Add failure comment to PR | |
if: ${{ failure() }} | |
uses: octokit/[email protected] | |
with: | |
route: POST /repos/{repository}/issues/{issue_number}/comments | |
repository: ${{ github.repository }} | |
issue_number: ${{ github.event.issue.number }} | |
body: \[Fast Forward CI\] PR cannot be merged in. Check the Actions tab for details. | |
env: | |
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }} |