Skip to content

Edgio Init

Edgio Init #1

Workflow file for this run

name: Deploy branch to Edgio
on:
push:
branches: [master, main]
pull_request:
release:
types: [published]
jobs:
setup-edgio:
name: Setup Edgio
if: "!contains(github.event.head_commit.message, 'skip-ci')"
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- uses: actions/checkout@v3
with:
repository: ${{ github.event.pull_request.head.repo.full_name }}
ref: ${{ github.event.pull_request.head.ref }}
- uses: actions/setup-node@v3
with:
node-version: 16
- name: Check for file existence
id: check-for-file
run: |
if git ls-files --error-unmatch "edgio.config.js" >/dev/null 2>&1; then
echo "Edgio config file exists. Skipping setup"
echo "SUCCESS=true" >> $GITHUB_ENV
else
echo "Edgio config file not found. Starting setup..."
echo "SUCCESS=false" >> $GITHUB_ENV
fi
- name: Install dependencies
if: env.SUCCESS == 'false'
run: |
# Check if package-lock.json file exists
if [ -f "package-lock.json" ]; then
# Use npm
npm i -g @edgio/cli@latest
else
# Check if yarn.lock file exists
if [ -f "yarn.lock" ]; then
# Use yarn
yarn global add @edgio/cli@latest
else
# No lock file found
echo "No lock file found. Please run 'npm i' or 'yarn install' to install dependencies."
exit 1
fi
fi
- name: Initialize Edgio
if: env.SUCCESS == 'false'
run: |
edgio init --connector=@edgio/nuxt
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Commit & Push changes
if: env.SUCCESS == 'false'
uses: EndBug/add-and-commit@v9
with:
committer_name: "Edgio Bot"
committer_email: "support@edg.io"
message: "Initialize Edgio"
fetch: true
deploy-to-edgio:
name: Deploy to Edgio
permissions:
contents: write
pull-requests: write
if: ${{ always() && !contains(github.event.head_commit.message, 'skip-ci') }}
needs: setup-edgio
runs-on: ubuntu-latest
env:
deploy_token: ${{secrets.EDGIO_DEPLOY_TOKEN}}
api_url: 'https://api.edgio.app'
steps:
- name: Check for deploy token secret
if: env.deploy_token == ''
run: |
echo You must define the "EDGIO_DEPLOY_TOKEN" secret in GitHub project settings
exit 1
- name: Extract branch name
shell: bash
run: |
if [[ "${{ github.ref }}" == "refs/pull/"* ]]; then
BRANCH_NAME=$(echo "${{ github.head_ref }}" | sed 's/\//_/g')
else
BRANCH_NAME=$(echo "${{ github.ref }}" | sed 's/refs\/heads\///g' | sed 's/\//_/g')
fi
echo "BRANCH_NAME=$BRANCH_NAME" >> $GITHUB_ENV
- uses: actions/checkout@v3
with:
repository: ${{ github.event.pull_request.head.repo.full_name }}
ref: ${{ github.event.pull_request.head.ref }}
- uses: actions/setup-node@v2
with:
node-version: 16
- name: Cache node modules
uses: actions/cache@v2
id: cache-node-modules
with:
path: ~/.npm # npm cache files are stored in `~/.npm` on Linux/macOS
key: ${{ runner.os }}-build-${{ hashFiles('**/package-lock.json') }}-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-build-${{ hashFiles('**/package-lock.json') }}-
${{ runner.os }}-build-${{ hashFiles('**/yarn.lock') }}-
${{ runner.os }}-build-
${{ runner.os }}-
- name: Display file contents
run: |
cd ${{ github.workspace }}
ls -al # Display the list of files in the workspace directory
- name: Determine Package Manager
id: package
run: |
# Check if package-lock.json file exists
if [ -f "package-lock.json" ]; then
package_manager="npm"
# Check if yarn.lock file exists
elif [ -f "yarn.lock" ]; then
package_manager="yarn"
else
echo "No lock file found. Please run 'npm i' or 'yarn install' to install dependencies."
exit 1
fi
echo "package_manager=$package_manager" >> $GITHUB_OUTPUT
- name: Install dependencies
run: |
if [ ${{ steps.package.outputs.package_manager }} = "npm" ]; then
npm i -g @edgio/cli@latest
npm ci --legacy-peer-deps
echo "Using npm - Global packages"
elif [ ${{ steps.package.outputs.package_manager }} = "yarn" ]; then
yarn global add @edgio/cli@latest
yarn install --frozen-lockfile
echo "Using yarn - Global packages"
fi
echo ${{ steps.package.outputs.package_manager }}
- name: Deploy
id: deploy
run: |
if [ "${{ steps.package.outputs.package_manager }}" = "npm" ]; then
deploy_command="npm run edgio:deploy --"
else
deploy_command="yarn edgio:deploy --"
fi
deploy_command="$deploy_command"
if [[ "$GITHUB_EVENT_NAME" == "push" ]]; then
deploy_command+=" --environment=staging"
elif [[ "$GITHUB_EVENT_NAME" == "release" ]]; then
deploy_command+=" --environment=production"
fi
deploy_command+=" --token='${{ secrets.EDGIO_DEPLOY_TOKEN }}'"
deploy_command+=" --non-interactive --branch='$BRANCH_NAME' --api-url='${{ env.api_url }}'"
eval "$deploy_command"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Parse Deploy Output
id: parse
run: |
sudo apt-get install -y jq
permalink=$(jq -r '.url' .edgio/deployment-manifest.json)
edge=$(jq -r '.environment.url' .edgio/deployment-manifest.json)
echo "PERMALINK=$permalink" >> $GITHUB_OUTPUT
echo "EDGE=$edge" >> $GITHUB_OUTPUT
- uses: jwalton/gh-find-current-pr@v1
id: finder
- name: Publish Preview Link
uses: marocchino/sticky-pull-request-comment@v2.2.0
with:
number: ${{ steps.finder.outputs.pr }}
header: preview
message: |
##### Deployment Links:
- Permalink: ${{ steps.parse.outputs.permalink }}
- Edge: ${{ steps.parse.outputs.edge }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}