|
| 1 | +name: Build image |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main] |
| 6 | +env: |
| 7 | + REGISTRY: docker.io |
| 8 | + IMAGE_NAME: yuntijs/gql-sdk-generator |
| 9 | + DOCKER_USER: yuntijs |
| 10 | + |
| 11 | +jobs: |
| 12 | + image: |
| 13 | + runs-on: ubuntu-latest |
| 14 | + steps: |
| 15 | + - uses: actions/checkout@v4 |
| 16 | + with: |
| 17 | + fetch-depth: 0 |
| 18 | + - name: Set Variable |
| 19 | + id: set-env |
| 20 | + run: | |
| 21 | + TAG=$(git describe --tags --abbrev=0 --match 'v*' 2> /dev/null) || true |
| 22 | + if [ -z "$TAG" ]; then |
| 23 | + echo "No tag found, use v0.0.1 as default" |
| 24 | + TAG=v0.0.1 |
| 25 | + fi |
| 26 | + echo "TAG=${TAG}" >> $GITHUB_OUTPUT |
| 27 | + echo "DATE=$(TZ=Asia/Shanghai date +'%Y%m%d')" >> $GITHUB_OUTPUT |
| 28 | + - name: Show Variable |
| 29 | + run: echo "varibables ${{ steps.set-env.outputs.TAG }}-${{ steps.set-env.outputs.DATE }}" |
| 30 | + - name: Extract metadata (tags, labels) for Docker |
| 31 | + id: meta |
| 32 | + uses: docker/metadata-action@v5 |
| 33 | + with: |
| 34 | + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} |
| 35 | + - name: Set up QEMU |
| 36 | + uses: docker/setup-qemu-action@v3 |
| 37 | + - name: Set up Docker Buildx |
| 38 | + uses: docker/setup-buildx-action@v3 |
| 39 | + with: |
| 40 | + buildkitd-flags: --debug |
| 41 | + config-inline: | |
| 42 | + [worker.oci] |
| 43 | + max-parallelism = 1 |
| 44 | + - name: Login to the dockerhub Registry |
| 45 | + uses: docker/login-action@v3 |
| 46 | + with: |
| 47 | + username: ${{ env.DOCKER_USER }} |
| 48 | + password: ${{ secrets.DOCKER_TOKEN }} |
| 49 | + - uses: benjlevesque/[email protected] |
| 50 | + name: Get short commit sha |
| 51 | + id: short-sha |
| 52 | + - name: setting token to npmrc |
| 53 | + run: | |
| 54 | + echo '//dev-npm.tenxcloud.net/:_authToken="${{ secrets.NPMTOKEN }}"' > /tmp/npmrc |
| 55 | + - name: Build and push |
| 56 | + id: push |
| 57 | + uses: docker/build-push-action@v5 |
| 58 | + with: |
| 59 | + context: . |
| 60 | + file: Dockerfile |
| 61 | + platforms: linux/amd64,linux/arm64 |
| 62 | + tags: | |
| 63 | + ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest |
| 64 | + ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.set-env.outputs.TAG }} |
| 65 | + ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:v${{ steps.set-env.outputs.DATE }}-${{ steps.short-sha.outputs.sha }} |
| 66 | + ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.set-env.outputs.TAG }}-${{ steps.set-env.outputs.DATE }}-${{ steps.short-sha.outputs.sha }} |
| 67 | + ${{ steps.meta.outputs.tags }} |
| 68 | + push: true |
| 69 | + build-args: | |
| 70 | + BUILD_ID=${{ env.SEMREV_LABEL }} |
| 71 | + BUILD_DATE=${{ env.BUILD_DATE }} |
| 72 | + secret-files: | |
| 73 | + "npmrc=/tmp/npmrc" |
0 commit comments