Skip to content

[FEAT]: _posts: Add 2024-05-22-using-azure-container-registry.md #607

[FEAT]: _posts: Add 2024-05-22-using-azure-container-registry.md

[FEAT]: _posts: Add 2024-05-22-using-azure-container-registry.md #607

name: Continuous deployment
on:
push:
pull_request:
jobs:
build:
runs-on: ubuntu-latest
env:
deploy_staging: ${{ github.event_name == 'pull_request' || (github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master')) }}
outputs:
deploy_staging: ${{ env.deploy_staging }}
defaults:
run:
shell: bash
working-directory: ./src
steps:
- name: Checkout πŸ›ŽοΈ
uses: actions/checkout@v2 # If you're using actions/checkout@v2 you must set persist-credentials to false in most cases for the deployment to work correctly.
with:
persist-credentials: false
- name: Cache πŸ’Ύ
uses: actions/cache@v2
with:
path: ${{ github.workspace }}/.next/cache
key: ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json') }}
- name: Setup node πŸ”§ # This example project is built using npm and outputs the result to the 'build' folder. Replace with the commands required to build your project, or remove this step entirely if your site is pre-built.
uses: actions/setup-node@v2
with:
node-version: "14"
env:
CI: true
- name: Export static site πŸ’»
run: |
npm install
npm run export
cp -r .circleci _static
touch _static/.nojekyll
working-directory: ${{ github.workspace }}
- name: Cache build artifacts πŸ“¦
if: ${{env.deploy_staging == 'true'}}
uses: actions/cache@v2
with:
path: ${{ github.workspace }}/_static
key: ${{ runner.os }}-static-site-${{ github.sha }}
stage:
runs-on: ubuntu-latest
needs: build
env:
heroku_api_key: ${{ secrets.HEROKU_API_KEY }}
heroku_email: ${{ secrets.HEROKU_EMAIL }}
heroku_app: ${{ secrets.HEROKU_STAGING_APP }}
if: needs.build.outputs.deploy_staging == 'true'
defaults:
run:
shell: bash
working-directory: ./src
steps:
- name: Check secrets πŸ”
run: |
error_flag=false
if [[ -z "${heroku_email}" ]]; then
echo Cannot find heroku mail! Add it to the repo secrets as HEROKU_EMAIL
error_flag=true
else
echo Heroku email found
fi
if [[ -z "${heroku_app}" ]]; then
echo Cannot find heroku deploy app name! Add it to the repo secrets as HEROKU_STAGING_APP
error_flag=true
else
echo Heroku deploy app name found
fi
if [[ -z "${heroku_api_key}" ]]; then
echo Cannot find api key! Add it to the repo secrets as HEROKU_API_KEY
error_flag=true
else
echo Heroku api key found
fi
if [ "$error_flag" = true ]; then
exit 1
fi
working-directory: ${{ github.workspace }}
- name: Checkout πŸ›ŽοΈ
uses: actions/checkout@v2 # If you're using actions/checkout@v2 you must set persist-credentials to false in most cases for the deployment to work correctly.
with:
persist-credentials: false
- name: Setup heroku CLI πŸ› 
run: |
curl https://cli-assets.heroku.com/install-ubuntu.sh | sh
cat >~/.netrc <<EOF
machine api.heroku.com
login ${heroku_email}
password ${heroku_api_key}
machine git.heroku.com
login ${heroku_email}
password ${heroku_api_key}
EOF
mkdir heroku
working-directory: ${{ github.workspace }}
- name: Restore build artifacts cache πŸ“¦
uses: actions/cache@v2
with:
path: ${{ github.workspace }}/_static
key: ${{ runner.os }}-static-site-${{ github.sha }}
- name: Deploy to staging πŸš€
run: |
cp -r .github/tests/* heroku
cp -r _static heroku
cd heroku
cat >.gitignore <<EOF
node_modules/
EOF
cat >Procfile <<EOF
web: npm install && npm start
EOF
git init
git config --global user.email "${heroku_email}"
git config --global user.name "Github Action"
# heroku git:remote -a "${heroku_app}"
# heroku login
git add -A
git commit -am "make it better"
# git push heroku master --force
working-directory: ${{ github.workspace }}
# - name: Create comment on pr 🧾
# uses: mshick/add-pr-comment@v1
# with:
# message: |
# Beep boop. I am a bot πŸ€–
#
# I have built your static site πŸ› 
# and deployed it in a staging environment 🚒
#
# You can check out the result at [${{ env.heroku_app }}.herokuapp.com]( http://${{ env.heroku_app }}.herokuapp.com )
#
# And approve (or reject) the results [here](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})
#
# repo-token: ${{ secrets.GITHUB_TOKEN }}
# repo-token-user-login: "github-actions[bot]" # The user.login for temporary GitHub tokens
# Only deploy if it's a pull request or a push on main (or master)
deploy:
runs-on: ubuntu-latest
needs: stage
#if: ${{ needs.build.outputs.deploy_staging }}
defaults:
run:
shell: bash
working-directory: ./src
environment:
name: staging_environment
steps:
- name: Checkout πŸ›ŽοΈ
uses: actions/checkout@v3 # If you're using actions/checkout@v2 you must set persist-credentials to false in most cases for the deployment to work correctly.
with:
persist-credentials: false
- name: Create dir for artifacts
run: |
mkdir _static
working-directory: ${{ github.workspace }}
- name: Restore build artifacts cache πŸ“¦
uses: actions/cache@v2
with:
path: ${{ github.workspace }}/_static
key: ${{ runner.os }}-static-site-${{ github.sha }}
- name: Deploy production πŸš€
uses: JamesIves/[email protected]
with:
token: ${{ secrets.GITHUB_TOKEN }}
branch: gh-pages # The branch the action should deploy to.
folder: ${{ github.workspace }}/_static # The folder the action should deploy.
clean: true # Automatically remove deleted files from the deploy branch