|
| 1 | +name: tag and release new version |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request_target: |
| 5 | + types: |
| 6 | + - closed |
| 7 | + |
| 8 | +jobs: |
| 9 | + tag: |
| 10 | + name: create git tag |
| 11 | + if: github.event.pull_request.merged == true && github.event.pull_request.base.ref == github.event.repository.default_branch |
| 12 | + runs-on: ubuntu-latest |
| 13 | + outputs: |
| 14 | + tag: v${{ steps.bump.outputs.version }} |
| 15 | + steps: |
| 16 | + - id: app-token |
| 17 | + uses: actions/create-github-app-token@v1 |
| 18 | + with: |
| 19 | + app-id: ${{ vars.RELEASE_APP_ID }} |
| 20 | + private-key: ${{ secrets.RELEASE_APP_SECRET }} |
| 21 | + - uses: actions/checkout@v4 |
| 22 | + with: |
| 23 | + token: ${{ steps.app-token.outputs.token }} |
| 24 | + ref: ${{ github.event.repository.default_branch }} |
| 25 | + - id: bump |
| 26 | + uses: ./.github/actions/bump |
| 27 | + |
| 28 | + relase: |
| 29 | + name: create new release |
| 30 | + needs: tag |
| 31 | + if: ${{ needs.tag.outputs.tag }} |
| 32 | + runs-on: ubuntu-latest |
| 33 | + permissions: |
| 34 | + contents: write |
| 35 | + steps: |
| 36 | + - uses: actions/github-script@v7 |
| 37 | + env: |
| 38 | + TAG: ${{ needs.tag.outputs.tag }} |
| 39 | + with: |
| 40 | + script: | |
| 41 | + const { TAG } = process.env |
| 42 | + github.rest.repos.createRelease({ |
| 43 | + owner: context.repo.owner, |
| 44 | + repo: context.repo.repo, |
| 45 | + tag_name: TAG, |
| 46 | + }) |
| 47 | +
|
| 48 | + build-docker: |
| 49 | + name: build docker image |
| 50 | + needs: tag |
| 51 | + if: ${{ needs.tag.outputs.tag }} |
| 52 | + runs-on: ubuntu-latest |
| 53 | + permissions: |
| 54 | + packages: write |
| 55 | + contents: read |
| 56 | + steps: |
| 57 | + - name: Checkout |
| 58 | + uses: actions/checkout@v4 |
| 59 | + with: |
| 60 | + ref: ${{ needs.tag.outputs.tag }} |
| 61 | + - name: Set up Docker Buildx |
| 62 | + uses: docker/setup-buildx-action@v3 |
| 63 | + - name: Login to GitHub Container Registry |
| 64 | + uses: docker/login-action@v3 |
| 65 | + with: |
| 66 | + registry: ghcr.io |
| 67 | + username: ${{ github.actor }} |
| 68 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 69 | + - name: Login to ECR |
| 70 | + uses: docker/login-action@v3 |
| 71 | + with: |
| 72 | + registry: ${{ vars.AWS_ACCOUNT_ID }}.dkr.ecr.${{ vars.AWS_REGION }}.amazonaws.com |
| 73 | + username: ${{ vars.AWS_ACCESS_KEY_ID }} |
| 74 | + password: ${{ secrets.AWS_SECRET_ACCESS_KEY }} |
| 75 | + - name: Set up Docker metadata |
| 76 | + id: meta |
| 77 | + uses: docker/metadata-action@v5 |
| 78 | + with: |
| 79 | + images: | |
| 80 | + ghcr.io/stapi-spec/stapi-fastapi |
| 81 | + ${{ vars.AWS_ACCOUNT_ID }}.dkr.ecr.${{ vars.AWS_REGION }}.amazonaws.com/stapi-spec/stapi-fastapi |
| 82 | + - name: Build and push |
| 83 | + uses: docker/build-push-action@v5 |
| 84 | + with: |
| 85 | + context: . |
| 86 | + target: lambda |
| 87 | + push: true |
| 88 | + platforms: linux/amd64 |
| 89 | + provenance: false |
| 90 | + tags: ${{ steps.meta.outputs.tags }} |
| 91 | + labels: ${{ steps.meta.outputs.labels }} |
| 92 | + |
| 93 | + deploy: |
| 94 | + runs-on: ubuntu-latest |
| 95 | + needs: |
| 96 | + - tag |
| 97 | + - build-docker |
| 98 | + if: ${{ needs.tag.outputs.tag }} |
| 99 | + steps: |
| 100 | + - uses: actions/checkout@v4 |
| 101 | + - run: pipx install poetry==1.7.1 |
| 102 | + - uses: actions/setup-python@v5 |
| 103 | + with: |
| 104 | + python-version: "3.12" |
| 105 | + cache: poetry |
| 106 | + - name: Install deploy dependencies |
| 107 | + run: poetry install --only=deploy-aws |
| 108 | + - name: Run CDK deploy |
| 109 | + uses: ./.github/actions/cdk-deploy |
| 110 | + with: |
| 111 | + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} |
| 112 | + AWS_ACCESS_KEY_ID: ${{ vars.AWS_ACCESS_KEY_ID }} |
| 113 | + AWS_ECR_REPOSITORY_ARN: arn:aws:ecr:${{ vars.AWS_REGION }}:${{ vars.AWS_ACCOUNT_ID}}:repository/stapi-spec/stapi-fastapi |
| 114 | + IMAGE_TAG_OR_DIGEST: ${{ needs.tag.outputs.tag }} |
0 commit comments