From 1d0fadeaf6b6b424087f6a2e8d764d2a7fe2ab94 Mon Sep 17 00:00:00 2001 From: phil Date: Mon, 16 Dec 2024 02:44:52 +0100 Subject: [PATCH] CI: add test and build --- .forgejo/workflows/build.yaml | 107 ++++++++++++++++++++++++++++++++++ package.json | 2 +- 2 files changed, 108 insertions(+), 1 deletion(-) create mode 100644 .forgejo/workflows/build.yaml diff --git a/.forgejo/workflows/build.yaml b/.forgejo/workflows/build.yaml new file mode 100644 index 0000000..6c5f912 --- /dev/null +++ b/.forgejo/workflows/build.yaml @@ -0,0 +1,107 @@ +on: + push: + workflow_dispatch: + inputs: + build: + description: "Build container" + required: true + default: false + type: boolean + +jobs: + build: + runs-on: container + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Get the version from git + id: version + run: echo "version=$(git describe --dirty --tags)" >> $GITHUB_OUTPUT + + - name: Check if the container should be built + id: builder + env: + RUN: ${{ toJSON(inputs.build || !contains(steps.version.outputs.version, '-')) }} + run: | + echo "run=$RUN" >> $GITHUB_OUTPUT + echo "Run build: $RUN" + + - name: Info - version and if the image container should be built + env: + VERSION: ${{ steps.version.outputs.version }} + RUN: ${{ steps.builder.outputs.run }} + FORCE: ${{ toJSON(inputs.build) }} + run: | + echo "Version $VERSION, force (manual input): $FORCE, run the build: $RUN" + + - uses: pnpm/action-setup@v4 + name: Install pnpm + with: + run_install: false + + - name: Install Node.js + uses: actions/setup-node@v4 + with: + node-version: 20 + cache: "pnpm" + + - name: Install dependencies + run: pnpm install + + - name: Update version.json from git describe + run: pnpm run version + + - name: Set the version in package.json + env: + VERSION: ${{ steps.version.outputs.version }} + run: sed "s/0.0.0/${VERSION}/" -i package.json + + - name: Build package (transpile ts => js) + run: ng build + + - name: Set registry token for pnpm" + env: + LOCAL_NPM_TOKEN: ${{ secrets.LOCAL_NPM_TOKEN }} + run: pnpm set "//code.philo.ydns.eu/api/packages/philorg/npm/:_authToken=${LOCAL_NPM_TOKEN}" + + - name: Publish + if: fromJSON(steps.builder.outputs.run) + run: pnpm publish --no-git-checks + + - name: Build container + if: fromJSON(steps.builder.outputs.run) + uses: actions/buildah-build@v1 + with: + image: gisaf-frontend + oci: true + labels: gisaf-frontend + tags: latest ${{ steps.version.outputs.version }} + containerfiles: | + ./Containerfile + build-args: | + APP_VERSION=${{ steps.version.outputs.version }} + + - name: Workaround for bug of podman-login + if: fromJSON(steps.builder.outputs.run) + run: | + mkdir -p $HOME/.docker + echo "{ \"auths\": {} }" > $HOME/.docker/config.json + + - name: Log in to container registry (with another workaround) + if: fromJSON(steps.builder.outputs.run) + uses: actions/podman-login@v1 + with: + registry: ${{ vars.REGISTRY }} + username: ${{ secrets.REGISTRY_USER }} + password: ${{ secrets.REGISTRY_PASSWORD }} + auth_file_path: /tmp/auth.json + + - name: Push the image to the registry + if: fromJSON(steps.builder.outputs.run) + uses: actions/push-to-registry@v2 + with: + registry: "docker://${{ vars.REGISTRY }}/${{ vars.ORGANISATION }}" + image: gisaf-frontend + tags: latest ${{ steps.version.outputs.version }} diff --git a/package.json b/package.json index 0faa655..ed38858 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "gisaf-frontend", "displayName": "Gisaf web front-end", - "version": "0.1.0", + "version": "0.0.0", "license": "GPL-3.0", "description": "Gisaf Geomatics", "repository": {