From 3cdcbc935e3396aaf3d48da1368168c8229d27e5 Mon Sep 17 00:00:00 2001 From: Kai Waldrant Date: Wed, 7 Aug 2024 09:18:37 +0200 Subject: [PATCH 1/2] add build (#21) --- .github/workflows/build.yaml | 135 +++++++++++++++++++++++++++++++++++ 1 file changed, 135 insertions(+) create mode 100644 .github/workflows/build.yaml diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml new file mode 100644 index 0000000..1ae0dd6 --- /dev/null +++ b/.github/workflows/build.yaml @@ -0,0 +1,135 @@ +name: Build + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +on: + workflow_call: + inputs: + version: + type: string + description: | + The version of the project to build. Example: `1.0.3`. + + If not provided, a development build with a version name + based on the branch name will be built. Otherwise, a release + build with the provided version will be built. + required: false + +jobs: + # phase 1 + target: + name: Build target branch + runs-on: ubuntu-latest + permissions: + contents: write + + outputs: + target_branch: ${{ steps.build-target.outputs.target_branch }} + version: ${{ steps.build-target.outputs.version }} + docker_matrix: ${{ steps.build-target.outputs.docker_matrix }} + + steps: + - name: Check out repository + uses: actions/checkout@v4 + with: + submodules: 'recursive' + fetch-depth: 0 + + - name: Install Viash + uses: viash-io/viash-actions/setup@v6 + + - name: Determine variables + id: variables + run: | + VERSION="${{ github.event.inputs.version }}" + SOURCE_BRANCH=$(echo "$GITHUB_REF" | sed 's/refs\/heads\///') + + if [[ -z $VERSION ]]; then + TARGET_BRANCH="build/$SOURCE_BRANCH" + VERSION=$(echo "$TARGET_BRANCH" | sed 's/[^a-zA-Z0-9_]/_/g') + else + if [[ ! "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+.*$ ]]; then + echo "Version '$VERSION' does not match PEP440" + exit 1 + fi + TARGET_BRANCH="release/${VERSION%.*}.x" + fi + + echo "Set version of Viash package to '$VERSION'" + echo "version=$VERSION" >> $GITHUB_OUTPUT + + echo "Set target branch to '$TARGET_BRANCH'" + echo "target_branch=$TARGET_BRANCH" >> $GITHUB_OUTPUT + + + - uses: viash-io/viash-actions/project/build-target@v6 + id: build-target + with: + target_branch: ${{ steps.variables.outputs.target_branch }} + version: ${{ steps.variables.outputs.version }} + + + + - name: Deploy to target branch + uses: peaceiris/actions-gh-pages@v4 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + publish_branch: ${{ steps.variables.outputs.target_branch }} + publish_dir: . + + # phase 2 + docker: + name: Build and push Docker images + needs: target + + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + strategy: + fail-fast: false + matrix: + component: ${{ fromJson(needs.target.outputs.docker_matrix) }} + + steps: + # Remove unnecessary files to free up space. Otherwise, we get 'no space left on device.' + - uses: data-intuitive/reclaim-the-bytes@v2 + + - uses: actions/checkout@v4 + with: + submodules: 'recursive' + ref: ${{ needs.target.outputs.target_branch }} + + - uses: viash-io/viash-actions/setup@v6 + + - name: Login to container registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build image + run: | + ${{matrix.component.executable}} ---engine docker ---setup build ---verbose + + - name: Push image + run: | + ${{matrix.component.executable}} ---engine docker ---setup push ---verbose + + # Add step to copy files to . + - name: Copy executables to root + run: | + echo "Copying directories to root" + cp -r target/executable/common/* . + + # Add step to remove unnecessary files + - name: Clean up + run: | + echo "Cleaning up" + rm -rf target + rm -rf src + rm _viash.yaml \ No newline at end of file From 6cee6171a330fb4eca1e81ec2dc7c62bee0c647a Mon Sep 17 00:00:00 2001 From: Kai Waldrant Date: Wed, 7 Aug 2024 10:22:52 +0200 Subject: [PATCH 2/2] Feature/no ref/add ci (#22) * add build * [WIP] change how build is triggered --- .github/workflows/build.yaml | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 1ae0dd6..fcbdd67 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -4,18 +4,7 @@ concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true -on: - workflow_call: - inputs: - version: - type: string - description: | - The version of the project to build. Example: `1.0.3`. - - If not provided, a development build with a version name - based on the branch name will be built. Otherwise, a release - build with the provided version will be built. - required: false +on: workflow_dispatch jobs: # phase 1