Skip to content

Ako/test workflow #96

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
name: "Generate Sitemap.xml and Robots.txt"
name: "Generate Sitemap.xml"
description: "Generate Sitemap.xml and robots.txt for all domains and upload to R2"
inputs:
main_domain:
description: "Main domain for sitemap replacement"
required: true
base_domain:
description: "Base domain for sitemap download"
required: true
runs:
using: "composite"
steps:
- name: Download sitemap.xml
shell: bash
env:
BASE_DOMAIN: ${{ inputs.base_domain }}
run: curl --create-dirs -O --output-dir ./content -O $BASE_DOMAIN/sitemap.xml

- name: Replace sitemap URLs and create directories
shell: bash
env:
MAIN_DOMAIN: ${{ inputs.main_domain }}
run: |
mkdir content
domain_name=$(echo $MAIN_DOMAIN | sed 's|https://||g')
mkdir -p content/$domain_name
cp sitemap.xml content/$domain_name/sitemap.xml
cp robots.txt content/$domain_name/robots.txt
node .github/modify_sitemap.js --new-domain $domain_name --input-file content/$domain_name/sitemap.xml
node .github/modify_robots.js --sitemap-url $domain_name --input-file content/$domain_name/robots.txt
rm sitemap.xml robots.txt
node .github/modify_sitemap.js --new-domain $domain_name --input-file ./content/sitemap.xml
5 changes: 4 additions & 1 deletion .github/actions/upload_to_r2/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ inputs:
r2_bucket_name:
description: 'R2 Bucket Name'
required: true
source_dir:
description: 'Source directory to upload'
required: true
runs:
using: 'composite'
steps:
Expand All @@ -23,5 +26,5 @@ runs:
r2-access-key-id: ${{ inputs.r2_access_key_id }}
r2-secret-access-key: ${{ inputs.r2_secret_access_key }}
r2-bucket: ${{ inputs.r2_bucket_name }}
source-dir: ./content/deriv.com
source-dir: ${{ inputs.source_dir }}
destination-dir: .
8 changes: 4 additions & 4 deletions .github/modify_robots.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const yargs = require("yargs");

// Function to update Sitemap entry in robots.txt
function updateSitemap(inputFile, newSitemapUrl) {
fs.readFile(inputFile, "utf8", (err, data) => {
fs.readFile(inputFile, "utf-8", (err, data) => {
if (err) {
console.error("Error reading the file:", err);
return;
Expand All @@ -13,16 +13,16 @@ function updateSitemap(inputFile, newSitemapUrl) {
if (data.match(/^Sitemap:/m)) {
newContent = data.replace(
/^Sitemap: .*/m,
`Sitemap: https://seo.deriv.com/${newSitemapUrl}/sitemap.xml`
`Sitemap: https://urls.deriv.com/sitemap.xml`
);
} else {
newContent =
data + `\nSitemap: https://seo.deriv.com/${newSitemapUrl}/sitemap.xml`;
data + `\nSitemap: https://urls.deriv.com/sitemap.xml`;
}
if (data.match(/^Host:/m)) {
newContent = newContent.replace(/^Host: .*/m, `Host: https://${newSitemapUrl}`);
}
fs.writeFile(inputFile, newContent, "utf8", (err) => {
fs.writeFile(inputFile, newContent, "utf-8", (err) => {
if (err) {
console.error("Error writing the file:", err);
return;
Expand Down
4 changes: 2 additions & 2 deletions .github/modify_sitemap.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const newDomain = argv["new-domain"];
const inputFile = argv["input-file"];
// Define the new domain
// Read the input file
fs.readFile(inputFile, "utf8", (err, data) => {
fs.readFile(inputFile, "utf-8", (err, data) => {
if (err) {
console.error("Error reading the file:", err);
return;
Expand All @@ -37,7 +37,7 @@ fs.readFile(inputFile, "utf8", (err, data) => {
const newContent = data.replace(pattern, `https://${newDomain}`);

// Write the modified content to the output file
fs.writeFile(inputFile, newContent, "utf8", (err) => {
fs.writeFile(inputFile, newContent, "utf-8", (err) => {
if (err) {
console.error("Error writing the file:", err);
return;
Expand Down
13 changes: 4 additions & 9 deletions .github/workflows/generate_sitemap.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,11 @@ jobs:
shell: bash
run: npm install yargs

- name: Download sitemap.xml and robots.txt
shell: bash
env:
BASE_DOMAIN: "https://staging.deriv.com"
run: |
curl -O $BASE_DOMAIN/sitemap.xml -O $BASE_DOMAIN/robots.txt

- name: Generate Sitemap and Robots.txt
uses: ./.github/actions/generate_sitemap_and_robots
- name: Generate Sitemap
uses: ./.github/actions/generate_sitemap
with:
main_domain: "https://deriv.com"
base_domain: "https://staging.deriv.com"

- name: Upload to R2
uses: ./.github/actions/upload_to_r2
Expand All @@ -38,3 +32,4 @@ jobs:
r2_access_key_id: ${{ secrets.R2_ACCESS_KEY_ID }}
r2_secret_access_key: ${{ secrets.R2_SECRET_ACCESS_KEY }}
r2_bucket_name: ${{ secrets.R2_BUCKET_NAME }}
source_dir: "./content"
13 changes: 4 additions & 9 deletions .github/workflows/publish-website.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,17 +90,11 @@ jobs:
shell: bash
run: npm install yargs

- name: Download sitemap.xml and robots.txt
shell: bash
env:
BASE_DOMAIN: "https://staging.deriv.com"
run: |
curl -O $BASE_DOMAIN/sitemap.xml -O $BASE_DOMAIN/robots.txt

- name: Generate Sitemap and Robots.txt
uses: ./.github/actions/generate_sitemap_and_robots
- name: Generate Sitemap
uses: ./.github/actions/generate_sitemap
with:
main_domain: "https://deriv.com"
base_domain: "https://staging.deriv.com"

- name: Upload to R2
uses: ./.github/actions/upload_to_r2
Expand All @@ -109,6 +103,7 @@ jobs:
r2_access_key_id: ${{ secrets.R2_ACCESS_KEY_ID }}
r2_secret_access_key: ${{ secrets.R2_SECRET_ACCESS_KEY }}
r2_bucket_name: ${{ secrets.R2_BUCKET_NAME }}
source_dir: "./content"

send_slack_failure:
runs-on: ubuntu-latest
Expand Down
Loading