Deploy to Aptible Staging #280
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 to Aptible Staging | |
# 1. Run tests on merges to main | |
# 2. (Attempt) to deploy to staging | |
# 3. if successful, draft release and merge main to staging branch | |
on: | |
workflow_run: | |
workflows: ["Run tests"] | |
types: [completed] | |
branches: [main] | |
workflow_dispatch: | |
inputs: { } | |
env: | |
USERNAME: ${{ secrets.GPR_USER }} | |
TOKEN: ${{ secrets.GPR_KEY }} | |
APTIBLE_BRANCH: staging | |
jobs: | |
deploy: | |
name: Deploy to Aptible Staging | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
ref: ${{ github.event.inputs.branch }} | |
fetch-depth: 0 | |
- name: Install SSH Key | |
uses: shimataro/ssh-key-action@v2.6.1 | |
with: | |
key: ${{ secrets.APTIBLE_SSH_PRIVATE_KEY }} | |
known_hosts: ${{ secrets.APTIBLE_KNOWN_HOSTS }} | |
- name: Push to Aptible remote branch | |
run: git push --force ${{ vars.APTIBLE_REMOTE_URL_STAGING }} "${GITHUB_SHA}:staging-deploy" | |
- name: Set Aptible environment variables and deploy | |
run: | | |
wget -O aptible-package https://omnibus-aptible-toolbelt.s3.amazonaws.com/aptible/omnibus-aptible-toolbelt/master/206/pkg/aptible-toolbelt_0.16.5%2B20200508143656~ubuntu.16.04-1_amd64.deb | |
sudo dpkg -i aptible-package | |
aptible login --email=${{ secrets.APTIBLE_USERNAME }} --password=${{ secrets.APTIBLE_PASSWORD}} | |
aptible deploy --app app-staging --git-commitish ${GITHUB_SHA} \ | |
'SPRING_PROFILES_ACTIVE=staging' \ | |
'DEFAULT_LOCALE=en' \ | |
'SPRING_DATASOURCE_URL=${{ secrets.SPRING_DATASOURCE_URL_STAGING }}' \ | |
'AWS_ACCESS_KEY=${{ secrets.AWS_ACCESS_KEY }}' \ | |
'AWS_SECRET_KEY=${{ secrets.AWS_SECRET_KEY }}' \ | |
'AWS_BUCKET=${{ secrets.AWS_BUCKET_STAGING }}' \ | |
'AWS_CMK=${{ secrets.AWS_CMK_STAGING }}' \ | |
'SENTRY_DSN=${{ secrets.SENTRY_DSN }}' \ | |
'SENTRY_ENVIRONMENT=staging' \ | |
'FORCE_SSL=true' \ | |
'ENCRYPTION_KEY=${{ secrets.ENCRYPTION_KEY }}' \ | |
'SPRING_DATASOURCE_USERNAME=${{ secrets.SPRING_DATASOURCE_USERNAME_STAGING }}' \ | |
'SPRING_DATASOURCE_PASSWORD=${{ secrets.SPRING_DATASOURCE_PASSWORD_STAGING }}' \ | |
'demo=true' \ | |
'RELEASE_HEALTHCHECK_TIMEOUT=900' | |
draft-release: | |
name: Draft a new release | |
needs: deploy | |
if: ${{ github.event.workflow_run.conclusion == 'success' }} | |
runs-on: ubuntu-latest | |
steps: | |
- name: Create tag name | |
id: create-tagname | |
run: echo "::set-output name=TAG_NAME::$(date +'%Y-%m-%d-%H%M')" | |
- name: Draft Release | |
id: create_release | |
uses: actions/create-release@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
tag_name: release-${{ steps.create-tagname.outputs.TAG_NAME }} | |
release_name: release-${{ steps.create-tagname.outputs.TAG_NAME }} | |
commitish: ${{ github.event.inputs.branch }} | |
body: | | |
Fill in details about this release | |
draft: true | |
prerelease: true | |
merge_to_staging: | |
name: Merge main -> staging | |
needs: deploy | |
if: ${{ github.event.workflow_run.conclusion == 'success' }} | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: '0' | |
ref: main | |
- uses: MaximeHeckel/github-action-merge-fast-forward@v1.1.1 | |
with: | |
branchtomerge: main | |
branch: staging | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |