Skip to content

Luau Shop Menu Seems Glitchy #284

Luau Shop Menu Seems Glitchy

Luau Shop Menu Seems Glitchy #284

Workflow file for this run

name: Fast Forward
# Ref: https://medium.com/@_samkitjain/override-githubs-merge-strategies-cea7eb789e23
on:
issue_comment:
types: [created, edited]
jobs:
fast_forward:
name: fast-forward
# Ref: https://docs.github.com/en/actions/using-jobs/assigning-permissions-to-jobs
# contents: For adding the commit
# issues: For adding the success/failure comments
# pull-requests: For some reason, even though I gave write perms to issues, it wasn't able to send the success/failure comment to PR, so maybe having pull-requests to write will?
permissions:
contents: write
issues: write
pull-requests: write
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') || contains(github.event.comment.body, '/fast-forward-force'))
steps:
- name: Fetch repository
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GH_TOKEN }}
# API: https://docs.github.com/en/rest/pulls/pulls?apiVersion=2022-11-28#get-a-pull-request
- name: Get PR deatils
uses: octokit/request-action@v2.x
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: View PR Details
# run: echo '${{ steps.get-pr-details.outputs.data }}'
# - name: View the github context
# run: echo "$GITHUB_CONTEXT"
# env:
# GITHUB_CONTEXT: ${{ toJson(github) }}
- name: Set environment variables
run: |
MERGE_STATUS=${{ fromJson(steps.get-pr-details.outputs.data).mergeable_state }}
if [ "$MERGE_STATUS" != "clean" ]; 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 == 'clean' || contains(github.event.comment.body, '/fast-forward-force')
run: |
git config --global user.email "<>"
git config --global user.name "GitHub Actions [Bot]"
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
# Executes the python script to copy the changelog from the PR's body to docs/changelogs/latest.md file
# It also saves the response into response.txt at the repo's base
# Cuts the lines before "## Changelog" line in the PR's body using the "sed" command
# Ref: https://stackoverflow.com/a/35966027
- name: Copy the changelogs from pr message to latest.md
if: env.MERGE_STATUS == 'clean' || contains(github.event.comment.body, '/fast-forward-force')
run: |
cd ./docs/changelogs
echo "$ISSUE_BODY" > pr_msg.txt
sed -i '/## Changelog/,$!d' ./pr_msg.txt
python ./scripts/copy_changelogs_to.py ./pr_msg.txt ./latest.md > ../../response.txt
cat ../../response.txt
rm ./pr_msg.txt
cd ../../
env:
ISSUE_BODY: ${{ github.event.issue.body }}
# Commit the changes if there was no error i.e., there was no issue in fetching the files and there was actually a changelog found/copied
- name: Commit the changes (if any)
if: env.MERGE_STATUS == 'clean' || contains(github.event.comment.body, '/fast-forward-force')
run: |
if [[ "$( tail ./response.txt -n 1 )" = 'No changes to write!' ]] || [[ "$( tail ./response.txt -n 1 )" =~ "File \`(.*?)\` not found\!" ]]; then
echo "COMMENT=${{ env.COMMENT }}\nNo changelogs found..." >> $GITHUB_ENV
else
git add docs/changelogs/latest.md
git commit -m ":memo: Add changelogs from #${{ github.event.issue.number }} to latest.md"
echo "COMMENT=${{ env.COMMENT }}\nCopied the changelogs from pull request body to docs/changelogs/latest.md..." >> $GITHUB_ENV
fi
- name: Push to origin
if: env.MERGE_STATUS == 'clean' || contains(github.event.comment.body, '/fast-forward-force')
run: |
git push origin
echo "COMMENT=${{ env.COMMENT }}\nPushed the changes to origin." >> $GITHUB_ENV
# Post a success/failure comment to the PR.
- name: Add success/failure comment to PR
uses: octokit/request-action@v2.x
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/request-action@v2.x
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 }}