Skip to content
This repository was archived by the owner on Apr 2, 2025. It is now read-only.

Commit 710d865

Browse files
committed
ci: tag, release, build and deploy on merge
1 parent 6f8ccce commit 710d865

File tree

2 files changed

+148
-0
lines changed

2 files changed

+148
-0
lines changed

.github/actions/bump/action.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: bump version
2+
description: bump version
3+
outputs:
4+
version:
5+
description: new version
6+
value: ${{ steps.bump.outputs.version }}
7+
runs:
8+
using: "composite"
9+
steps:
10+
- shell: bash
11+
run: pipx install poetry==1.7.1
12+
- shell: bash
13+
run: |
14+
git config --local user.name "github-actions[bot]"
15+
git config --local user.email "github-actions[bot]@users.noreply.github.com"
16+
git config --local pull.rebase true
17+
- id: bump
18+
shell: bash
19+
env:
20+
BRANCH: ${{ github.event.repository.default_branch }}
21+
run: |
22+
export OLD=$(poetry version --short)
23+
export BASE=$(echo ${OLD} | cut -d "+" -f 1)
24+
export NEW=${BASE}+$(date +%y%m%d-%H%M%S)
25+
26+
poetry version ${NEW}
27+
git add pyproject.toml
28+
git commit -m "bump: ${OLD} → ${NEW}"
29+
git tag v${NEW}
30+
31+
git pull origin ${BRANCH}
32+
git push origin HEAD:${BRANCH} --tags
33+
34+
echo "version=v${NEW}" >> "$GITHUB_OUTPUT"
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
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

Comments
 (0)