feat: on tag publish deploy to envs (#220) #202
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: Publish and Deploy Image | |
on: | |
push: | |
branches: [ "main" ] | |
release: | |
types: [published, edited] | |
workflow_dispatch: | |
env: | |
AWS_REGION: ${{ secrets.AWS_REGION }} | |
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
jobs: | |
publish: | |
runs-on: ubuntu-latest | |
outputs: | |
deploy_tag: ${{ steps.build.outputs.deploy_tag }} | |
steps: | |
- | |
uses: actions/checkout@v3 | |
- | |
name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
- | |
name: Login to Public ECR | |
uses: docker/login-action@v2 | |
with: | |
registry: public.ecr.aws | |
username: ${{ env.AWS_ACCESS_KEY_ID }} | |
password: ${{ env.AWS_SECRET_ACCESS_KEY }} | |
env: | |
AWS_REGION: us-east-1 | |
- | |
name: Build and Publish | |
id: build | |
run: | | |
SHA_TAG=$(echo ${{ github.SHA }} | head -c 12) | |
DEPLOY_TAG=$SHA_TAG | |
if [[ ${{ contains(github.event.head_commit.message, 'chore: Release') }} == 'true' ]]; then | |
RELEASE_TAG=$(cargo metadata --format-version=1 --no-deps | jq '.packages[0].version' | tr -d '"') | |
# Use the release tag to deploy, if one is available. | |
DEPLOY_TAG=$RELEASE_TAG | |
fi | |
# make SHA="${{ github.SHA }}" SHA_TAG="$SHA_TAG" RELEASE_TAG="$RELEASE_TAG" publish-docker | |
echo "Deploy tag:" | |
echo ${DEPLOY_TAG} | |
echo "deploy_tag=${DEPLOY_TAG}" >> $GITHUB_OUTPUT | |
deploy: | |
runs-on: ubuntu-latest | |
needs: | |
- publish | |
steps: | |
- | |
uses: actions/checkout@v3 | |
- | |
# TODO: Uncomment and remove echo | |
name: Schedule k8s deployment | |
run: | | |
echo "Workflow triggered by: ${{ github.event_name }}" | |
if [[ "${{github.event_name}}" == "release" ]]; then | |
echo "Release action: ${{ github.event.action }}" | |
if [${{ github.event.release.prerelease }}]; then | |
DEPLOY_ENV="tnet" | |
else | |
DEPLOY_ENV="prod" | |
fi | |
else | |
DEPLOY_ENV="qa" | |
fi | |
# make DEPLOY_ENV="$DEPLOY_ENV" DEPLOY_TAG=${{ needs.publish.outputs.deploy_tag }} schedule-k8s-deployment | |
echo "DEPLOY_ENV is $DEPLOY_ENV" |