Created
February 5, 2021 15:55
-
-
Save orta/21fe5533f35c8675cc78ea20ed6b69f6 to your computer and use it in GitHub Desktop.
Upload GitHub Action
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: Upload infra | |
on: | |
push: | |
branches: | |
- main | |
- prod | |
jobs: | |
build-and-deploy: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@master | |
- uses: actions/setup-node@v1 | |
with: | |
node-version: "12.x" | |
# - name: Dump GitHub context | |
# env: | |
# GITHUB_CONTEXT: ${{ toJson(github) }} | |
# run: echo "$GITHUB_CONTEXT" | |
- run: "yarn install" | |
- run: "node scripts/repoLint.js" | |
# To keep one yml, we set the environments for staging vs prod ahead of time | |
- name: Set prod env | |
if: ${{ github.ref == 'refs/heads/prod' }} | |
run: | | |
echo "AZURE_STATIC_WEB_APPS_API_TOKEN=$(echo $PROD_AZURE_STATIC_WEB_APPS_API_TOKEN)" >> $GITHUB_ENV | |
echo "FUNC_APP=kisservices-production" >> $GITHUB_ENV | |
echo "FUNCS_URL=https://api.kisservices.dev" >> $GITHUB_ENV | |
echo "FUNCTIONS_DEPLOY_PROFILE=$(echo $PROD_FUNCTIONS_DEPLOY_PROFILE)" >> $GITHUB_ENV | |
echo "DEPLOY_TYPE=Prod" >> $GITHUB_ENV | |
echo "STRIPE_PUB_KEY=pk_live_51HZNb0Kjk5Zy6fGqOq3GH9N5V9qokDWgofYc1xGJN6sQjBwAYPJciCUfpOC8EZoXqGvmQmoOSXmao39tgR28ov4a00JfWsUkxt" >> $GITHUB_ENV | |
env: | |
PROD_AZURE_STATIC_WEB_APPS_API_TOKEN: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN_PROUD_GLACIER_0EE68890F }} | |
PROD_FUNCTIONS_DEPLOY_PROFILE: ${{ secrets.KISS_DEPLOY_PROFILE }} | |
- name: Set staging env | |
if: ${{ github.ref == 'refs/heads/main' }} | |
run: | | |
echo "AZURE_STATIC_WEB_APPS_API_TOKEN=$(echo $STAGING_AZURE_STATIC_WEB_APPS_API_TOKEN)" >> $GITHUB_ENV | |
echo "FUNC_APP=kisservices-staging" >> $GITHUB_ENV | |
echo "FUNCS_URL=https://api-staging.kisservices.dev" >> $GITHUB_ENV | |
echo "FUNCTIONS_DEPLOY_PROFILE=$(echo $STAGING_FUNCTIONS_DEPLOY_PROFILE)" >> $GITHUB_ENV | |
echo "DEPLOY_TYPE=Staging" >> $GITHUB_ENV | |
echo "STRIPE_PUB_KEY=pk_test_51HZNb0Kjk5Zy6fGqt3fg4DVedSdQiplNN4XzgAIzf7p26DVURQoplgyzrXzZw89l9It5ZZ2AuE3He8hh5qHymC7k00BXO6AIkT" >> $GITHUB_ENV | |
env: | |
STAGING_AZURE_STATIC_WEB_APPS_API_TOKEN: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN_ORANGE_FIELD_0B6DD910F }} | |
STAGING_FUNCTIONS_DEPLOY_PROFILE: ${{ secrets.KISS_STAGING_DEPLOY_PROFILE }} | |
- run: "yarn build" | |
- run: "yarn test" | |
- run: "yarn check-site" | |
- name: Prepare Web | |
run: | | |
echo "Use GitHub for process.env" | |
rm dashboard/.env | |
echo "Support the upcoming npm install" | |
npm install -g json | |
json -I -f dashboard/package.json -e "this.devDependencies['@kiss/functions']='file:../functions'" | |
- name: Deploy Zoom Dashboard | |
uses: Azure/[email protected] | |
with: | |
action: "upload" | |
app_artifact_location: "public" | |
app_location: "dashboard" | |
azure_static_web_apps_api_token: ${{ env.AZURE_STATIC_WEB_APPS_API_TOKEN }} | |
repo_token: ${{ secrets.GITHUB_TOKEN }} | |
env: | |
KISS_SERVICES_FUNCS_URL: ${{ env.FUNCS_URL }} | |
STRIPE_PUBLISHABLE_KEY: ${{ env.STRIPE_PUB_KEY }} | |
- name: "Setup for deploy" | |
run: | | |
echo ::group:: Undoing Monorepo | |
rm yarn.lock | |
rm package.json | |
rm -rf node_modules | |
echo ::endgroup:: | |
echo ::group:: Setting up functions | |
cd functions | |
yarn install --production | |
echo ::endgroup:: | |
## Upload the Subscriptions app | |
- uses: Azure/functions-action@v1 | |
with: | |
app-name: ${{ env.FUNC_APP }} | |
publish-profile: ${{ env.FUNCTIONS_DEPLOY_PROFILE }} | |
package: functions | |
- name: Set commit message in ENV | |
run: echo COMMIT_MESSAGE=$(echo "${{ github.event.head_commit.message }}" | tr '\n' ' ') >> $GITHUB_ENV | |
- name: Success slack notification | |
env: | |
INCOMING_WEBHOOK_URL: ${{ secrets.SLACK_DEPLOY_WEBHOOK }} | |
DEPLOY_TYPE: ${{ env.DEPLOY_TYPE }} | |
uses: tokorom/action-slack-incoming-webhook@main | |
with: | |
text: "Deployed ${{env.DEPLOY_TYPE}} by ${{github.actor}}: ${{ github.event.head_commit.ref }} '${{env.COMMIT_MESSAGE}}'" | |
- name: Fail slack notification | |
if: ${{ failure() }} | |
env: | |
INCOMING_WEBHOOK_URL: ${{ secrets.SLACK_DEPLOY_WEBHOOK }} | |
DEPLOY_TYPE: ${{ env.DEPLOY_TYPE }} | |
uses: tokorom/action-slack-incoming-webhook@main | |
with: | |
text: "Deploy for ${{env.DEPLOY_TYPE}} failed" | |
attachments: | | |
[ | |
{ | |
"color": "danger", | |
"author_name": "${{ github.actor }}", | |
"author_icon": "${{ github.event.sender.avatar_url }}", | |
"fields": [ | |
{ | |
"title": "Commit Message", | |
"value": "${{ env.COMMIT_MESSAGE }}" | |
}, | |
{ | |
"title": "GitHub Actions URL", | |
"value": "${{ github.event.repository.url }}/actions/runs/${{ github.run_id }}?check_suite_focus=true" | |
}, | |
{ | |
"title": "Compare URL", | |
"value": "${{ github.event.compare }}" | |
} | |
] | |
} | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment