diff --git a/.github/actions/build/action.yml b/.github/actions/build/action.yml index 446a3d1..bbe2db3 100644 --- a/.github/actions/build/action.yml +++ b/.github/actions/build/action.yml @@ -20,13 +20,6 @@ outputs: runs: using: "composite" steps: - - name: Validate inputs - shell: bash - run: | - if [[ "${{ inputs.push }}" == "true" && "${{ github.ref }}" == "refs/heads/main" ]]; then - echo "Cannot push to registry from main branch unless we migrate our main build job to GHA." - exit 1 - fi # Setup docker to build for multiple architectures - name: Set up QEMU uses: docker/setup-qemu-action@v3 diff --git a/.github/actions/deploy/action.yml b/.github/actions/deploy/action.yml new file mode 100644 index 0000000..8d7e55e --- /dev/null +++ b/.github/actions/deploy/action.yml @@ -0,0 +1,26 @@ +name: 'Deploy to fly' +description: 'Deploys a published image to fly' +inputs: + image: + required: true + description: "Which image to deploy" + default: "false" + app: + required: true + description: "Which environment to deploy to" + token: + required: true + description: "Access token for flyctl" + +runs: + using: "composite" + steps: + - name: Deploy to fly + shell: bash + run: | + flyctl deploy \ + -t ${{ inputs.token }} \ + -i ${{ inputs.image }} \ + -a ${{ inputs.app }} \ + --yes \ + --verbose diff --git a/.github/workflows/merge.yml b/.github/workflows/merge.yml index f565c38..41bb2db 100644 --- a/.github/workflows/merge.yml +++ b/.github/workflows/merge.yml @@ -7,39 +7,37 @@ on: branches: - main +env: + environment: staging + jobs: - log: - runs-on: ubuntu-latest - steps: - - name: Log event - run: | - echo "json: ${{ github }}" - printenv deploy_staging: if: ${{ github.event_name == 'merge_group' }} runs-on: ubuntu-latest steps: - - name: Checkout - uses: actions/checkout@v2 + - uses: actions/checkout@v2 - id: build uses: ./.github/actions/build with: push: true username: ${{ github.actor}} password: ${{ secrets.GITHUB_TOKEN }} - - name: Deploy to staging - run: | - echo "Deploying to staging" - # Your deployment script here + + - name: Deploy to (${{ env.environment }}) + uses: ./.github/actions/deploy + with: + app: ${{ env.environment }} + token: ${{ secrets.FLY_TOKEN }} + iamge: ${{ steps.build.outputs.tags }} - name: Notify (scuccessful deployment) if: success() uses: ./.github/actions/slack with: - message: ":tada: Deployed to staging :white_check_mark: successfully!" + message: ":tada: Deployed to ${{ env.environment }} :white_check_mark: successfully!" webhook_url: ${{ secrets.SLACK_WEBHOOK_URL }} - name: Notify (failed deployment) if: failure() uses: ./.github/actions/slack with: - message: ":fail: Failed to deploy to staging :red_flag: successfully!" + message: ":fail: Failed to deploy to ${{ env.environment }} :red_flag: successfully!" webhook_url: ${{ secrets.SLACK_WEBHOOK_URL }} diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index 668775c..aeff6dc 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -5,6 +5,9 @@ on: branches: - main +env: + environment: production + jobs: log: runs-on: ubuntu-latest @@ -23,20 +26,22 @@ jobs: push: true username: ${{ github.actor}} password: ${{ secrets.GITHUB_TOKEN }} - - name: Deploy to production - run: | - echo "Deploying to production" - # Your deployment script here + + - name: Deploy to (${{ env.environment }}) + uses: ./.github/actions/deploy + with: + app: ${{ env.environment }} + token: ${{ secrets.FLY_TOKEN }} + iamge: ${{ steps.build.outputs.tags }} - name: Notify (scuccessful deployment) if: success() uses: ./.github/actions/slack with: - message: ":tada: Deployed to production :white_check_mark: successfully!" + message: ":tada: Deployed to ${{ env.environment }} :white_check_mark: successfully!" webhook_url: ${{ secrets.SLACK_WEBHOOK_URL }} - name: Notify (failed deployment) if: failure() uses: ./.github/actions/slack with: - message: ":fail: Failed to deploy to production :red_flag: successfully!" + message: ":fail: Failed to deploy to ${{ env.environment }} :red_flag: successfully!" webhook_url: ${{ secrets.SLACK_WEBHOOK_URL }} -