Add note about correct _in
operator array syntax
#75
Workflow file for this run
This file contains hidden or 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: Open Redirects PR | |
on: | |
pull_request: | |
types: closed | |
jobs: | |
check-approval: | |
runs-on: ubuntu-latest | |
if: github.event.pull_request.merged == true | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
with: | |
fetch-depth: 0 | |
- name: Grab all the renamed or deleted files | |
id: grab-renamed | |
run: | | |
if git diff --name-status ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }} -- docs/ | grep -E 'R|D'; then | |
# output variable to pass to the next step that sets the diff-status to true | |
echo "diff-status=true" >> "$GITHUB_OUTPUT" | |
# diff work and parsing the paths to get them in the right shape | |
diff_files=$(git diff --name-status ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }} -- docs/ | grep -E 'R|D') | |
diff_files=$(echo "$diff_files" | sed 's|.mdx|/|g') | |
diff_files=$(echo "$diff_files" | sed 's|docs/||g') | |
# print the diff so each line is a new line in diff_files.txt | |
echo "$diff_files" | tr " " "\n" > diff_files.txt | |
# grab the filenames and plug them into our nginx template | |
set +e | |
while IFS= read -r line; do | |
OLD=$(echo "$line" | awk '{print $2}') | |
NEW=$(echo "$line" | awk '{print $3}') | |
if [ -z "$NEW" ]; then | |
NEW="OG-FILE-WAS-DELETED-REPLACE-ME-WITH-NEW-LOCATION" | |
fi | |
read -r -d '' TEMPLATE << EOM | |
# TEST ME: https://stage.hasura.io/docs/3.0/$OLD | |
location = /docs/3.0/$OLD { | |
return 301 https://\$host/docs/3.0/$NEW; | |
} | |
EOM | |
echo -e "\n$TEMPLATE\n" >> nginx.txt | |
echo "This is a redirect:\n\n $TEMPLATE" | |
done < diff_files.txt | |
set -e | |
echo "NGINX<<EOF" >> "$GITHUB_ENV" | |
cat nginx.txt >> "$GITHUB_ENV" | |
echo "EOF" >> "$GITHUB_ENV" | |
else | |
echo "diff-status=false" >> "$GITHUB_OUTPUT" | |
fi | |
- name: Checkout the hasura.io repository | |
if: steps.grab-renamed.outputs.diff-status == 'true' | |
uses: actions/checkout@v2 | |
with: | |
repository: hasura/hasura.io | |
path: hasura.io | |
token: ${{ secrets.DOCS_GITHUB_TOKEN }} | |
- name: Create new branch and update redirects | |
if: steps.grab-renamed.outputs.diff-status == 'true' | |
run: | | |
cd hasura.io | |
PR_NUMBER=${{ github.event.pull_request.number }} | |
PR_TITLE="${{ github.event.pull_request.title }}" | |
BRANCH_NAME="docs-redirects-${PR_NUMBER}" | |
REDIRECTS_FILE="redirects/paths/docs.conf" | |
TIMESTAMP=$(date +"%d/%m/%Y") | |
cat <<EOF >> $REDIRECTS_FILE | |
################################################################## | |
# PR #$PR_NUMBER - $TIMESTAMP | |
################################################################## | |
$NGINX | |
EOF | |
- name: create pull request | |
if: steps.grab-renamed.outputs.diff-status == 'true' | |
uses: peter-evans/[email protected] | |
with: | |
path: hasura.io | |
token: ${{ secrets.DOCS_GITHUB_TOKEN }} | |
author: hasura-bot <[email protected]> | |
commit-message: 'Redirects: DDN DOCS PR#${{ github.event.pull_request.number }}' | |
branch: docs-redirects-${{ github.event.pull_request.number }} | |
base: master | |
title: 'Redirects: DDN Docs PR#${{ github.event.pull_request.number }}' | |
body: | | |
This PR adds _templated_ redirects for the merged docs PR hasura/ddn-docs#${{ github.event.pull_request.number }}. | |
Modify, review, and merge as needed. |