|
| 1 | +name: Publish CPU |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + |
| 6 | +jobs: |
| 7 | + push_to_registry: |
| 8 | + name: Build image |
| 9 | + runs-on: ubuntu-latest |
| 10 | + if: ${{ github.repository_owner == 'cloud-py-api' }} |
| 11 | + permissions: |
| 12 | + packages: write |
| 13 | + contents: read |
| 14 | + steps: |
| 15 | + - name: Set app env |
| 16 | + run: | |
| 17 | + # Split and keep last |
| 18 | + echo "APP_NAME=${GITHUB_REPOSITORY##*/}" >> $GITHUB_ENV |
| 19 | + echo "APP_VERSION=${GITHUB_REF##*/}" >> $GITHUB_ENV |
| 20 | +
|
| 21 | + - name: Checkout |
| 22 | + uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3 |
| 23 | + with: |
| 24 | + path: ${{ env.APP_NAME }} |
| 25 | + |
| 26 | + - name: Read package.json node and npm engines version |
| 27 | + uses: skjnldsv/read-package-engines-version-actions@0ce2ed60f6df073a62a77c0a4958dd0fc68e32e7 # v2.1 |
| 28 | + id: versions |
| 29 | + # Continue if no package.json |
| 30 | + continue-on-error: true |
| 31 | + with: |
| 32 | + path: ${{ env.APP_NAME }} |
| 33 | + fallbackNode: "^20" |
| 34 | + fallbackNpm: "^10" |
| 35 | + |
| 36 | + - name: Set up node ${{ steps.versions.outputs.nodeVersion }} |
| 37 | + # Skip if no package.json |
| 38 | + if: ${{ steps.versions.outputs.nodeVersion }} |
| 39 | + uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3 |
| 40 | + with: |
| 41 | + node-version: ${{ steps.versions.outputs.nodeVersion }} |
| 42 | + |
| 43 | + - name: Set up npm ${{ steps.versions.outputs.npmVersion }} |
| 44 | + # Skip if no package.json |
| 45 | + if: ${{ steps.versions.outputs.npmVersion }} |
| 46 | + run: npm i -g npm@"${{ steps.versions.outputs.npmVersion }}" |
| 47 | + |
| 48 | + - name: Build ${{ env.APP_NAME }} |
| 49 | + # Skip if no package.json |
| 50 | + if: ${{ steps.versions.outputs.nodeVersion }} |
| 51 | + run: | |
| 52 | + cd ${{ env.APP_NAME }} |
| 53 | + npm ci |
| 54 | + npm run build |
| 55 | +
|
| 56 | + - name: Set up QEMU |
| 57 | + uses: docker/setup-qemu-action@v3 |
| 58 | + - name: Set up Docker Buildx |
| 59 | + uses: docker/setup-buildx-action@v3 |
| 60 | + |
| 61 | + - name: Log in to GitHub Container Registry |
| 62 | + uses: docker/login-action@v3 |
| 63 | + with: |
| 64 | + registry: ghcr.io |
| 65 | + username: ${{ github.actor }} |
| 66 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 67 | + |
| 68 | + - name: Available platforms |
| 69 | + run: echo ${{ steps.buildx.outputs.platforms }} |
| 70 | + |
| 71 | + - name: Install xmlstarlet |
| 72 | + run: sudo apt-get update && sudo apt-get install -y xmlstarlet |
| 73 | + |
| 74 | + - name: Extract version from XML |
| 75 | + id: extract_version |
| 76 | + run: | |
| 77 | + cd ${{ env.APP_NAME }} |
| 78 | + VERSION=$(xmlstarlet sel -t -v "//image-tag" appinfo/info.xml) |
| 79 | + echo "VERSION=$VERSION" >> $GITHUB_ENV |
| 80 | +
|
| 81 | + - name: Log version |
| 82 | + run: | |
| 83 | + echo "Extracted version: ${{ env.VERSION }}" |
| 84 | +
|
| 85 | + - name: Build container image |
| 86 | + uses: docker/build-push-action@v5 |
| 87 | + with: |
| 88 | + push: true |
| 89 | + context: ./${{ env.APP_NAME }} |
| 90 | + platforms: linux/amd64,linux/arm64/v8 |
| 91 | + tags: ghcr.io/cloud-py-api/talk_bot_ai:${{ env.VERSION }} |
| 92 | + build-args: | |
| 93 | + BUILD_TYPE=cpu |
0 commit comments