Skip to content

fix: route versioning #120

fix: route versioning

fix: route versioning #120

Workflow file for this run

name: Continuous Deployment
on:
# push:
# branches:
# - development
# pull_request:
env:
PROJECT: Miwataru
STAGE: dev
AWS_DEFAULT_REGION: us-east-1
jobs:
# see: https://github.com/hashicorp/learn-terraform-github-actions
build-shared-infrastructure:
name: Build Shared Infrastructure
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./terraform
steps:
- name: Check out repository code
uses: actions/checkout@v3
- name: Setup Terraform
uses: hashicorp/setup-terraform@v1
with:
cli_config_credentials_token: ${{ secrets.TF_API_TOKEN }}
# see: https://www.terraform.io/language/values/variables#variable-definitions-tfvars-files
- name: Setup Terraform Variables
run: |
cat << EOF >> terraform.tfvars
project = "${{ env.PROJECT }}"
stage = "${{ env.STAGE }}"
aws_region = "${{ env.AWS_DEFAULT_REGION }}"
EOF
terraform fmt terraform.tfvars
- name: Terraform Format
id: fmt
run: terraform fmt -check
- name: Terraform Init
id: init
run: terraform init -backend-config=backend.${{ env.STAGE }}.hcl
- name: Terraform Validate
id: validate
run: terraform validate -no-color
- name: Terraform Plan
id: plan
if: github.event_name == 'pull_request'
run: terraform plan -no-color
continue-on-error: true
- uses: actions/github-script@v6
if: github.event_name == 'pull_request'
env:
PLAN: ${{ steps.plan.outputs.stdout }}
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const output = `
#### Terraform Format and Style 🖌\`${{ steps.fmt.outcome }}\`
#### Terraform Initialization ⚙️\`${{ steps.init.outcome }}\`
#### Terraform Validation 🤖\`${{ steps.validate.outcome }}\`
#### Terraform Plan 📖\`${{ steps.plan.outcome }}\`
<details><summary>Show Plan</summary>
\`\`\`terraform
${process.env.PLAN}
\`\`\`
</details>
*Pusher: @${{ github.actor }}, Action: \`${{ github.event_name }}\`*
`;
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: output
});
- name: Terraform Plan Status
if: steps.plan.outcome == 'failure'
run: exit 1
- name: Terraform Apply
if: github.ref == 'refs/heads/development' && github.event_name == 'push'
run: terraform apply -auto-approve
# see: https://github.com/serverless/github-action
build-app-specific-infrastructure:
name: Build App-Specific Infrastructure
needs: build-shared-infrastructure
if: github.ref == 'refs/heads/development' && github.event_name == 'push'
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./backend
strategy:
matrix:
node-version: [16.x]
steps:
- name: Check out repository code
uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- name: Cache Node.js modules
uses: actions/cache@v3
with:
path: ./backend/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Install Node.js dependencies
run: npm ci
- name: Cache Composer packages
uses: actions/cache@v3
with:
path: ./backend/vendor
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-
# see: https://bref.sh/docs/deploy.html#automating-deployments
- name: Install Composer dependencies
run: composer install --prefer-dist --optimize-autoloader --no-dev
- name: Install Serverless globally
run: npm install --location=global serverless
# see: https://github.com/aws-actions/configure-aws-credentials
- name: Configure AWS Environment Variables and Enable aws Command
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ env.AWS_DEFAULT_REGION }}
- name: Setup Environment Variables
run: |
serverless print \
--stage ${{ env.STAGE }} \
--path provider.environment \
| sed "s/: /=/" >> .env
# https://www.serverless.com/framework/docs/environment-variables#support-for-env-files
rm .env.${{ env.STAGE }}
env:
APP_KEY: ${{ secrets.APP_KEY }}
ADMIN_EMAIL: ${{ secrets.ADMIN_EMAIL }}
- name: Directory Permissions
run: chmod -R 777 storage bootstrap/cache
- name: Cache Bootstrap Files
run: php artisan optimize
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
- name: Serverless Deploy
run: serverless deploy --stage ${{ env.STAGE }} --verbose
- name: Compile Assets
run: npm run prod
- name: Synchronize Assets with S3 Buckets
run: |
S3_BUCKET=$(
aws ssm get-parameter \
--name "/${{ env.PROJECT }}/${{ env.STAGE }}/S3_BUCKET" \
--with-decryption \
--query Parameter.Value \
--output text \
)
aws s3 sync public/ s3://${S3_BUCKET}/public \
--delete \
--exclude index.php \
--acl public-read