Assistant v0 #197
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 Preview | |
on: | |
pull_request: | |
# Only allow one deploy-preview job per branch. The launch logic is idempotent, so we can just cancel | |
# any existing jobs and launch a new one. | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} | |
cancel-in-progress: true | |
jobs: | |
deploy-preview: | |
name: Deploy Preview | |
runs-on: ubuntu-latest | |
if: contains(github.event.pull_request.labels.*.name, 'preview') | |
steps: | |
- name: Configure AWS Credentials | |
uses: aws-actions/configure-aws-credentials@v4 | |
with: | |
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
aws-region: ${{ secrets.AWS_REGION }} | |
- name: Check out repository code | |
uses: actions/checkout@v4 | |
with: | |
ref: ${{ github.event.pull_request.head.sha }} | |
- name: Install dependencies including dev | |
run: make install-dev | |
- name: Setup SSH key | |
run: | | |
mkdir -p ~/.ssh | |
echo "${{ secrets.AWS_PEM }}" > ~/.ssh/armand-centrality.pem | |
chmod 600 ~/.ssh/armand-centrality.pem | |
echo -e "Host *\n\tStrictHostKeyChecking no\n\tIdentityFile ~/.ssh/armand-centrality.pem\n\n" > ~/.ssh/config | |
cat ~/.ssh/config | |
- name: Deploy Preview | |
id: deploy-preview | |
run: | | |
python deploy/deploy/aws/instances.py launch m7g.medium --checkout ${{ github.event.pull_request.head.sha }} --idempotency-token ${{ github.head_ref }} | |
- name: Save Preview URL | |
id: preview-url | |
run: | | |
URL=$(cat /tmp/preview-url) | |
echo ${URL} | |
ENVSET=PREVIEW_URL=${URL} | |
echo ${ENVSET} | |
echo "${ENVSET}" >> "$GITHUB_OUTPUT" | |
- name: Comment Preview URL | |
# Note: This is all AI generated | |
env: | |
REPO: ${{ github.repository }} | |
PREVIEW_URL: ${{ steps.preview-url.outputs.PREVIEW_URL }} | |
COMMENT_IDENTIFIER: "Preview Deployment:" | |
GH_TOKEN: ${{ github.token }} | |
PR_NUMBER: ${{ github.event.pull_request.number }} | |
run: | | |
# Search for an existing comment with the unique identifier | |
COMMENT_ID=$(gh api repos/${REPO}/issues/${PR_NUMBER}/comments --jq '.[] | select(.body | contains("'"$COMMENT_IDENTIFIER"'")) | .id') | |
if [ -z "$COMMENT_ID" ]; then | |
# Create new comment | |
gh pr comment $PR_NUMBER --body "$COMMENT_IDENTIFIER $PREVIEW_URL" --repo $REPO | |
else | |
# Update existing comment | |
gh api repos/$REPO/issues/comments/$COMMENT_ID --method PATCH --field body="$COMMENT_IDENTIFIER $PREVIEW_URL" | |
fi | |