Add notification.yml
& updates test.yml
#350
Workflow file for this run
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: Test deployment | |
on: | |
pull_request: | |
branches: | |
- main | |
jobs: | |
test-deploy: | |
name: Test deployment | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v2 | |
- uses: actions/setup-node@v3 | |
with: | |
node-version: 16.15.0 | |
cache: yarn | |
- name: Install dependencies | |
run: yarn install --frozen-lockfile | |
- name: Test build website | |
run: yarn build --locale en | |
check_version_changes: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
with: | |
fetch-depth: 10 | |
- name: Get and Parse File Diffs | |
id: parse_diffs | |
run: | | |
git fetch origin main:main | |
git diff main...HEAD 'versioned_docs/version-latest/protocol/pulsar.mdx' > pulsar_diff.txt | |
git diff main...HEAD 'versioned_docs/version-latest/protocol/substrate-cli.mdx' > substrate_cli_diff.txt | |
echo "---- CONTENT OF PULSAR DIFF ----" | |
cat pulsar_diff.txt | |
echo "---- CONTENT OF SUBSTRATE CLI DIFF ----" | |
cat substrate_cli_diff.txt | |
COMMENT_BODY="" | |
new_pulsar_tag="" | |
old_pulsar_tag="" | |
new_substrate_cli_tag="" | |
old_substrate_cli_tag="" | |
if [[ ! -s pulsar_diff.txt && ! -s substrate_cli_diff.txt ]]; then | |
echo "No changes detected in the specified files." | |
exit 0 | |
fi | |
# Process Pulsar changes | |
if [[ -s pulsar_diff.txt ]]; then | |
echo "---- Extracting Pulsar Tags ----" | |
new_pulsar_tag=$(grep -o "\\+.*https://github.com/subspace/pulsar/releases/download/[^/]\\+/[^/]\\+" pulsar_diff.txt | awk -F'/' '{print $8}') | |
old_pulsar_tag=$(grep -o "\\-.*https://github.com/subspace/pulsar/releases/download/[^/]\\+/[^/]\\+" pulsar_diff.txt | awk -F'/' '{print $8}') | |
echo "New Pulsar Tag: $new_pulsar_tag" | |
echo "Old Pulsar Tag: $old_pulsar_tag" | |
if [ -n "$new_pulsar_tag" ] && [ -n "$old_pulsar_tag" ] && [ "$new_pulsar_tag" != "$old_pulsar_tag" ]; then | |
echo "Found Changes in Pulsar. Adding to Comment Block" | |
COMMENT_BODY+="- [ ] Detected version change on Pulsar: $old_pulsar_tag -> $new_pulsar_tag\n" | |
fi | |
fi | |
# Process Substrate CLI changes | |
if [[ -s substrate_cli_diff.txt ]]; then | |
new_substrate_cli_tag=$(grep -o "\\+.*https://github.com/subspace/subspace/releases/download/[^/]\\+/[^/]\\+" substrate_cli_diff.txt | awk -F'/' '{print $8}') | |
old_substrate_cli_tag=$(grep -o "\\-.*https://github.com/subspace/subspace/releases/download/[^/]\\+/[^/]\\+" substrate_cli_diff.txt | awk -F'/' '{print $8}') | |
if [ -n "$new_substrate_cli_tag" ] && [ -n "$old_substrate_cli_tag" ] && [ "$new_substrate_cli_tag" != "$old_substrate_cli_tag" ]; then | |
echo "Found Changes in Substrate-CLI. Adding to Comment Block" | |
COMMENT_BODY+="- [ ] Detected version change on Advanced CLI: $old_substrate_cli_tag -> $new_substrate_cli_tag\n" | |
fi | |
fi | |
# Post comment if needed | |
if [ -n "$COMMENT_BODY" ]; then | |
COMMENT_BODY+="\nPlease check the checkboxes above to acknowledge that merging this PR will notify the Discord community." | |
echo "COMMENT_BODY=$COMMENT_BODY" >> $GITHUB_ENV | |
fi | |
- name: Comment on PR | |
if: ${{ env.COMMENT_BODY }} | |
run: | | |
PR_ID=$(jq -r ".number" "$GITHUB_EVENT_PATH") | |
COMMENT_BODY=$(echo -n "$COMMENT_BODY" | jq -Rr @uri) | |
RESPONSE=$(curl -s -o /dev/stderr -w "%{http_code}" -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ | |
-d "{\"body\":\"$COMMENT_BODY\"}" \ | |
"https://api.github.com/repos/$GITHUB_REPOSITORY/issues/$PR_ID/comments") | |
if [ "$RESPONSE" -ne 201 ]; then | |
echo "Failed to post comment" | |
exit 1 | |
fi |