chore: build things #2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: ci | |
| on: | |
| push: | |
| env: | |
| REGISTRY_IMAGE: samuel19982/smartorganizr | |
| jobs: | |
| test: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Set up Go | |
| uses: actions/setup-go@v4 | |
| with: | |
| go-version: 1.25 | |
| - name: Install Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 24 | |
| cache: 'npm' | |
| cache-dependency-path: ./ui/package-lock.json | |
| - name: Install dependencies | |
| run: npm install | |
| working-directory: ./ui | |
| - name: Build | |
| run: npm run build | |
| working-directory: ./ui | |
| - name: Move to golang | |
| run: | | |
| mv ./ui/dist ./api_go/ui/dist | |
| - name: Install dependencies | |
| run: go mod download | |
| working-directory: ./api_go | |
| - name: Set up Docker | |
| uses: docker/setup-docker-action@v4 | |
| - name: Test | |
| run: go test ./tests/ | |
| working-directory: ./api_go | |
| build: | |
| if: github.ref == 'refs/heads/master' | |
| needs: | |
| - test | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| include: | |
| - platform: linux/amd64 | |
| runs-on: ubuntu-latest | |
| - platform: linux/arm64 | |
| runs-on: ubuntu-24.04-arm | |
| runs-on: ${{ matrix.runs-on }} | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-tags: 'true' | |
| fetch-depth: '0' | |
| - name: Prepare | |
| run: | | |
| platform=${{ matrix.platform }} | |
| echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV | |
| - name: Docker meta | |
| id: meta | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: ${{ env.REGISTRY_IMAGE }} | |
| - name: Login to Docker Hub | |
| uses: docker/login-action@v3 | |
| with: | |
| username: samuel19982 | |
| password: ${{ secrets.DOCKER_PASSWORD }} | |
| - name: Set up QEMU | |
| uses: docker/setup-qemu-action@v3 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Build and push by digest | |
| id: build | |
| uses: docker/build-push-action@v6 | |
| with: | |
| platforms: ${{ matrix.platform }} | |
| labels: ${{ steps.meta.outputs.labels }} | |
| tags: ${{ env.REGISTRY_IMAGE }} | |
| outputs: type=image,push-by-digest=true,name-canonical=true,push=true | |
| - name: Export digest | |
| run: | | |
| mkdir -p ${{ runner.temp }}/digests | |
| digest="${{ steps.build.outputs.digest }}" | |
| touch "${{ runner.temp }}/digests/${digest#sha256:}" | |
| - name: Upload digest | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: digests-${{ env.PLATFORM_PAIR }} | |
| path: ${{ runner.temp }}/digests/* | |
| if-no-files-found: error | |
| retention-days: 1 | |
| merge: | |
| runs-on: ubuntu-latest | |
| if: github.ref == 'refs/heads/master' | |
| needs: | |
| - build | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-tags: 'true' | |
| fetch-depth: '0' | |
| - name: Download digests | |
| uses: actions/download-artifact@v4 | |
| with: | |
| path: ${{ runner.temp }}/digests | |
| pattern: digests-* | |
| merge-multiple: true | |
| - name: Login to Docker Hub | |
| uses: docker/login-action@v3 | |
| with: | |
| username: samuel19982 | |
| password: ${{ secrets.DOCKER_PASSWORD }} | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Docker meta | |
| id: meta | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: ${{ env.REGISTRY_IMAGE }} | |
| tags: | | |
| type=ref,event=branch | |
| type=ref,event=pr | |
| type=semver,pattern={{version}} | |
| type=semver,pattern={{major}}.{{minor}} | |
| - name: Get last tag and commit hash | |
| id: vars | |
| run: | | |
| TAG=$(git describe --tags --abbrev=0) | |
| HASH=$(git rev-parse --short HEAD) | |
| echo "IMAGE_TAG=${TAG}-${HASH}" >> $GITHUB_ENV | |
| - name: Create manifest list and push | |
| working-directory: ${{ runner.temp }}/digests | |
| run: | | |
| DIGEST_FLAGS=$(for f in *; do printf '%s@sha256:%s ' "$REGISTRY_IMAGE" "$f"; done) | |
| docker buildx imagetools create -t $REGISTRY_IMAGE:$IMAGE_TAG $DIGEST_FLAGS | |
| - name: Inspect image | |
| run: | | |
| docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }} | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| repository: 'SamTV12345/smartorganizr-charts' | |
| token: '${{ secrets.SMARTORGANIZR_CHARTS_PUSH_TOKEN }}' | |
| - name: Change argocd tag | |
| run: | | |
| sed -i "s|tag: .*|tag: \"${{ env.IMAGE_TAG }}\"|g" ./values-dynamic.yaml | |
| git config --global user.name 'github-actions' | |
| git config --global user.email 'noreply@github.com' | |
| git add . | |
| git commit -m "chore: bump image to ${{ env.IMAGE_TAG }}" | |
| git push origin main | |