Skip to content

i18n - Build and Deploy #2331

i18n - Build and Deploy

i18n - Build and Deploy #2331

Workflow file for this run

name: i18n - Build and Deploy
on:
workflow_dispatch:
schedule:
- cron: '0 0/6 * * *' # Build once every six hours
jobs:
build:
name: Build
runs-on: [self-hosted, on-aws]
strategy:
fail-fast: false
matrix:
node-version: [18.x]
languages:
[chinese, espanol, italian, japanese, korean, portuguese, ukrainian]
site_tlds: [org]
env:
BUILD_LANG: ${{ matrix.languages }}
ALGOLIA_API_KEY: ${{ secrets.ALGOLIA_API_KEY }}
ALGOLIA_APP_ID: ${{ secrets.ALGOLIA_APP_ID }}
CHINESE_GHOST_API_URL: ${{ secrets.CHINESE_GHOST_API_URL }}
CHINESE_GHOST_API_VERSION: ${{ secrets.CHINESE_GHOST_API_VERSION }}
CHINESE_GHOST_CONTENT_API_KEY: ${{ secrets.CHINESE_GHOST_CONTENT_API_KEY }}
ENGLISH_GHOST_API_URL: ${{ secrets.ENGLISH_GHOST_API_URL }}
ENGLISH_GHOST_API_VERSION: ${{ secrets.ENGLISH_GHOST_API_VERSION }}
ENGLISH_GHOST_CONTENT_API_KEY: ${{ secrets.ENGLISH_GHOST_CONTENT_API_KEY }}
ESPANOL_GHOST_API_URL: ${{ secrets.ESPANOL_GHOST_API_URL }}
ESPANOL_GHOST_API_VERSION: ${{ secrets.ESPANOL_GHOST_API_VERSION }}
ESPANOL_GHOST_CONTENT_API_KEY: ${{ secrets.ESPANOL_GHOST_CONTENT_API_KEY }}
FRENCH_GHOST_API_URL: ${{ secrets.FRENCH_GHOST_API_URL }}
FRENCH_GHOST_API_VERSION: ${{ secrets.FRENCH_GHOST_API_VERSION }}
FRENCH_GHOST_CONTENT_API_KEY: ${{ secrets.FRENCH_GHOST_CONTENT_API_KEY }}
ITALIAN_GHOST_API_URL: ${{ secrets.ITALIAN_GHOST_API_URL }}
ITALIAN_GHOST_API_VERSION: ${{ secrets.ITALIAN_GHOST_API_VERSION }}
ITALIAN_GHOST_CONTENT_API_KEY: ${{ secrets.ITALIAN_GHOST_CONTENT_API_KEY }}
JAPANESE_GHOST_API_URL: ${{ secrets.JAPANESE_GHOST_API_URL }}
JAPANESE_GHOST_API_VERSION: ${{ secrets.JAPANESE_GHOST_API_VERSION }}
JAPANESE_GHOST_CONTENT_API_KEY: ${{ secrets.JAPANESE_GHOST_CONTENT_API_KEY }}
KOREAN_GHOST_API_URL: ${{ secrets.KOREAN_GHOST_API_URL }}
KOREAN_GHOST_API_VERSION: ${{ secrets.KOREAN_GHOST_API_VERSION }}
KOREAN_GHOST_CONTENT_API_KEY: ${{ secrets.KOREAN_GHOST_CONTENT_API_KEY }}
PORTUGUESE_GHOST_API_URL: ${{ secrets.PORTUGUESE_GHOST_API_URL }}
PORTUGUESE_GHOST_API_VERSION: ${{ secrets.PORTUGUESE_GHOST_API_VERSION }}
PORTUGUESE_GHOST_CONTENT_API_KEY: ${{ secrets.PORTUGUESE_GHOST_CONTENT_API_KEY }}
UKRAINIAN_GHOST_API_URL: ${{ secrets.UKRAINIAN_GHOST_API_URL }}
UKRAINIAN_GHOST_API_VERSION: ${{ secrets.UKRAINIAN_GHOST_API_VERSION }}
UKRAINIAN_GHOST_CONTENT_API_KEY: ${{ secrets.UKRAINIAN_GHOST_CONTENT_API_KEY }}
URDU_GHOST_API_URL: ${{ secrets.URDU_GHOST_API_URL }}
URDU_GHOST_API_VERSION: ${{ secrets.URDU_GHOST_API_VERSION }}
URDU_GHOST_CONTENT_API_KEY: ${{ secrets.URDU_GHOST_CONTENT_API_KEY }}
ADS_ENABLED: ${{ secrets.ADS_ENABLED }}
GOOGLE_ADSENSE_DATA_AD_CLIENT: ${{ secrets.GOOGLE_ADSENSE_DATA_AD_CLIENT }}
GOOGLE_ADSENSE_DATA_AD_SLOT: ${{ secrets.GOOGLE_ADSENSE_DATA_AD_SLOT }}
POSTS_PER_PAGE: ${{ secrets.POSTS_PER_PAGE }}
SITE_DOMAIN: freecodecamp.${{ matrix.site_tlds }}
LOCALE_FOR_UI: ${{ matrix.languages }}
LOCALE_FOR_GHOST: ${{ matrix.languages }}
steps:
- name: Checkout source code
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@e33196f7422957bea03ed53f6fbb155025ffc7b8 # v3
with:
node-version: ${{ matrix.node-version }}
- name: Install dependencies
run: npm ci
- name: Build site
run: npm run build
env:
NODE_ENV: production
# - name: Set up Docker Buildx
# uses: docker/setup-buildx-action@dc7b9719a96d48369863986a06765841d7ea23f6 # tag=v2
- name: Docker login to Azure Container Registry
uses: azure/docker-login@83efeb77770c98b620c73055fbb59b2847e17dc0 # v1
with:
login-server: ${{ secrets.ACR_NAME }}.azurecr.io
username: ${{ secrets.ACR_USERNAME }}
password: ${{ secrets.ACR_PASSWORD }}
- name: Build & Push Docker Images
run: |
tagname=$(git rev-parse --short HEAD)-$(date +%Y%m%d)-$(date +%H%M)
docker build . \
--tag ${{ secrets.ACR_NAME }}.azurecr.io/${{ matrix.site_tlds }}/news-${{ matrix.languages }}:$tagname \
--tag ${{ secrets.ACR_NAME }}.azurecr.io/${{ matrix.site_tlds }}/news-${{ matrix.languages }}:latest \
--build-arg BUILD_LANGUAGE=${{ matrix.languages }} \
--file docker/Dockerfile
docker push --all-tags ${{ secrets.ACR_NAME }}.azurecr.io/${{ matrix.site_tlds }}/news-${{ matrix.languages }}
- name: Clean up Self-hosted setup
uses: colpal/actions-clean@36e6ca1abd35efe61cb60f912bd7837f67887c8a # tag=v1
if: ${{ always() }} # To ensure this step runs even when earlier steps fail
deploy:
name: Deploy
runs-on: ubuntu-20.04
needs:
- build
strategy:
fail-fast: false
matrix:
languages:
[chinese, espanol, italian, japanese, korean, portuguese, ukrainian]
site_tlds: [org]
# GitHub's deployment environment configuration.
# environment:
# name: ${{ matrix.site_tlds }}
# url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}
steps:
- name: Azure Login
uses: azure/login@92a5484dfaf04ca78a94597f4f19fea633851fa2 # tag=v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- name: Deploy to Azure Web App
id: deploy-to-webapp
uses: azure/webapps-deploy@fb8292eb575db1bb18a90627e8959cd51dbb355c # v2
with:
app-name: freecodecamp-news-${{ matrix.site_tlds }}-${{ matrix.languages }}
images:
${{ secrets.ACR_NAME }}.azurecr.io/${{ matrix.site_tlds }}/news-${{
matrix.languages }}:latest
- name: Remove Old images
run: |
az acr run \
--cmd "acr purge --filter '${{ matrix.site_tlds }}/news-${{ matrix.languages }}:.*' \
--untagged --ago 2d" \
--registry ${{ secrets.ACR_NAME }} /dev/null
# - name: Clean up Self-hosted setup
# uses: colpal/actions-clean@v1
# if: ${{ always() }} # To ensure this step runs even when earlier steps fail