diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml deleted file mode 100644 index cf9bfa35f..000000000 --- a/.github/workflows/docker.yml +++ /dev/null @@ -1,59 +0,0 @@ -name: Docker Build and Push - -on: - workflow_call: - inputs: - matrix: - description: 'JSON-encoded matrix' - required: true - type: string - push: - description: 'Whether to push the image to Docker Hub' - required: true - type: boolean - secrets: - DOCKER_USERNAME: - description: 'Docker Hub username' - required: true - DOCKER_TOKEN: - description: 'Docker Hub password' - required: true - -permissions: - contents: read - -jobs: - docker: - name: Docker "${{ matrix.package_name }}" - strategy: - matrix: ${{fromJson(inputs.matrix)}} - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v4 - - name: Get | Docker Tag - id: docker_tag - run: | - package_dir="${{ matrix.package_dir }}" - version=$(cat ${package_dir}/VERSION) - tag=polusai/${{ matrix.package_name }}:${version} - echo "tag=${tag}" >> $GITHUB_OUTPUT - - name: Setup | Docker Buildx - uses: docker/setup-buildx-action@v3 - - name: Login | DockerHub - uses: docker/login-action@v3 - with: - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_TOKEN }} - - name: Check | Image exists - run: | - tag=${{ steps.docker_tag.outputs.tag }} - docker pull ${tag} > /dev/null \ - && $(echo "::error::${tag} already exists on DockerHub" && exit 1) \ - || echo "success" - - name: Publish | Docker Image - uses: docker/build-push-action@v5 - with: - context: "{{defaultContext}}:${{ matrix.package_dir }}" - push: ${{ inputs.push }} - tags: ${{ steps.docker_tag.outputs.tag }} diff --git a/.github/workflows/package-filter.yml b/.github/workflows/package-filter.yml index 427bc9b8e..8eed2a121 100644 --- a/.github/workflows/package-filter.yml +++ b/.github/workflows/package-filter.yml @@ -8,6 +8,11 @@ on: required: true default: 0 type: number + ignore-missing-dev: + description: "If true, the action will ignore packages that do not have a dev version. Otherwise, the action will fail if any package does not have a dev version." + required: true + default: false + type: boolean outputs: matrix: description: "The directories containing the updated packages" @@ -79,7 +84,7 @@ jobs: done # Check that the version is a dev version - if [[ "$(cat ${pkg_dir}/VERSION)" != *"dev"* ]] + if [[ "$(cat ${pkg_dir}/VERSION)" != *"dev"* ]] || [[ ${{ inputs.ignore-missing-dev }} ]] then echo "::error::${pkg_dir} does not have a dev version" && exit 1 fi diff --git a/.github/workflows/package-release.yml b/.github/workflows/package-release.yml index 9ee5bc802..5e51cdf18 100644 --- a/.github/workflows/package-release.yml +++ b/.github/workflows/package-release.yml @@ -12,6 +12,11 @@ on: required: true default: 1 type: number + ignore-missing-dev: + description: "If true, the action will ignore packages that do not have a dev version. Otherwise, the action will fail if any package does not have a dev version." + required: true + default: true + type: boolean repo_name: description: 'Name of the base repository. The user can ignore this input if the action is triggered from the base repository.' required: true @@ -41,19 +46,20 @@ permissions: jobs: package-filter: - name: Filter for updated package + name: Filter for updated packages if: github.repository == 'polusai/${{ github.event.inputs.repo_name }}' uses: ./.github/workflows/package-filter.yml with: num-commits: ${{ fromJson(github.event.inputs.num-commits) }} + ignore-missing-dev: ${{ fromJson(github.event.inputs.ignore-missing-dev) }} package-release: - name: Release "${{ matrix.package_name }}" + name: Release | ${{ matrix.package_name }} if: github.repository == 'polusai/${{ github.event.inputs.repo_name }}' needs: package-filter strategy: fail-fast: false - matrix: ${{fromJson(needs.package-filter.outputs.matrix)}} + matrix: ${{ fromJson(needs.package-filter.outputs.matrix) }} runs-on: ubuntu-latest steps: - name: Checkout @@ -62,30 +68,30 @@ jobs: fetch-depth: 0 ref: ${{ github.event.inputs.branch }} persist-credentials: false - - name: Generate a token + - name: Token | Generate id: generate_token uses: actions/create-github-app-token@v1 with: app-id: ${{ secrets.APP_ID }} private-key: ${{ secrets.APP_PRIVATE_KEY }} - - name: Use the token + - name: Token | Use the token env: GH_TOKEN: ${{ steps.generate_token.outputs.token }} run: | gh api octocat - - name: Set up Python + - name: Python | Setup uses: actions/setup-python@v5 with: python-version: '3.9' - - name: Install bump2version + - name: Python | Install bump2version run: | python -m pip install --upgrade pip pip install bump2version - - name: Bump Version + - name: Python | Bump Version Release run: | cd "${{ matrix.package_dir }}" bump2version release --no-commit - - name: Commit all changed files + - name: Git | Commit env: CI_COMMIT_AUTHOR: polusai-auth-helper[bot] CI_COMMIT_EMAIL: ${{ secrets.APP_ID }}+polusai-auth-helper[bot]@users.noreply.github.com @@ -93,20 +99,35 @@ jobs: git config --global user.name "${{ env.CI_COMMIT_AUTHOR }}" git config --global user.email "${{ env.CI_COMMIT_EMAIL }}" git commit -a -m "build: Bumped release version for ${{ matrix.package_name }}" - - name: Push changes + - name: Git | Push uses: ad-m/github-push-action@master with: force: true github_token: ${{ steps.generate_token.outputs.token }} - - docker: - name: Build Docker images - if: github.repository == 'polusai/${{ github.event.inputs.repo_name }}' - needs: [package-filter, package-release] - uses: ./.github/workflows/docker.yml - with: - matrix: ${{ needs.package-filter.outputs.matrix }} - push: true - secrets: - DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} - DOCKER_TOKEN: ${{ secrets.DOCKER_TOKEN }} + - name: Docker | Tag + id: docker_tag + run: | + package_dir="${{ matrix.package_dir }}" + cp .gitignore ${package_dir}/.dockerignore + version=$(cat ${package_dir}/VERSION) + tag=polusai/${{ matrix.package_name }}:${version} + echo "tag=${tag}" >> $GITHUB_OUTPUT + - name: Docker | Setup Buildx + uses: docker/setup-buildx-action@v3 + - name: Docker | Login DockerHub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_TOKEN }} + - name: Docker | Check if Image exists + run: | + tag=${{ steps.docker_tag.outputs.tag }} + docker pull ${tag} > /dev/null \ + && $(echo "::error::${tag} already exists on DockerHub" && exit 1) \ + || echo "success" + - name: Docekr | Push Image + uses: docker/build-push-action@v5 + with: + context: "{{defaultContext}}:${{ matrix.package_dir }}" + push: true + tags: ${{ steps.docker_tag.outputs.tag }} diff --git a/.github/workflows/tests.yml b/.github/workflows/package-tests.yml similarity index 53% rename from .github/workflows/tests.yml rename to .github/workflows/package-tests.yml index d0505ba28..48e202d30 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/package-tests.yml @@ -1,9 +1,5 @@ name: Package tests -env: - DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} - DOCKER_TOKEN: ${{ secrets.DOCKER_TOKEN }} - on: pull_request: branches: @@ -16,13 +12,6 @@ on: - master - dev workflow_call: - secrets: - DOCKER_USERNAME: - description: 'Docker Hub username' - required: true - DOCKER_TOKEN: - description: 'Docker Hub password' - required: true permissions: contents: read @@ -33,13 +22,14 @@ jobs: uses: ./.github/workflows/package-filter.yml with: num-commits: 0 + ignore-missing-dev: false tests: - name: Test "${{ matrix.package_name }}" + name: Test | ${{ matrix.package_name }} needs: package-filter strategy: fail-fast: false - matrix: ${{fromJson(needs.package-filter.outputs.matrix)}} + matrix: ${{ fromJson(needs.package-filter.outputs.matrix) }} runs-on: ubuntu-latest steps: - name: Checkout @@ -69,14 +59,26 @@ jobs: poetry install poetry run pytest -v - - docker: - name: Build Docker images - needs: [package-filter, tests] - uses: ./.github/workflows/docker.yml - with: - matrix: ${{ needs.package-filter.outputs.matrix }} - push: false - secrets: - DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} - DOCKER_TOKEN: ${{ secrets.DOCKER_TOKEN }} + - name: Docker | Tag + id: docker_tag + run: | + package_dir="${{ matrix.package_dir }}" + version=$(cat ${package_dir}/VERSION) + tag=polusai/${{ matrix.package_name }}:${version} + echo "tag will be ${tag}" + echo "tag=${tag}" >> $GITHUB_OUTPUT + - name: Docker | Setup Buildx + uses: docker/setup-buildx-action@v3 + - name: Docker | Check if Image exists + run: | + tag=${{ steps.docker_tag.outputs.tag }} + docker pull ${tag} > /dev/null \ + && $(echo "::error::${tag} already exists on DockerHub" && exit 1) \ + || echo "success" + - name: Docker | Build Image + run: | + cp .gitignore ${{ matrix.package_dir }}/.dockerignore + cd "${{ matrix.package_dir }}" + tag=${{ steps.docker_tag.outputs.tag }} + docker build . -t ${tag} + # docker buildx build --platform linux/amd64,linux/arm64 -t ${tag} --push . diff --git a/.github/workflows/test-github-app.yml b/.github/workflows/test-github-app.yml deleted file mode 100644 index 5e1904d9a..000000000 --- a/.github/workflows/test-github-app.yml +++ /dev/null @@ -1,41 +0,0 @@ - -name: Test Github App -on: - workflow_dispatch: - -jobs: - auto_publish_job: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v4 - with: - ref: ${{ github.head_ref }} - fetch-depth: 0 - persist-credentials : false - - name: Generate a token - id: generate_token - uses: actions/create-github-app-token@v1 - with: - app-id: ${{ secrets.APP_ID }} - private-key: ${{ secrets.APP_PRIVATE_KEY }} - - - name: Use the token - env: - GH_TOKEN: ${{ steps.generate_token.outputs.token }} - run: | - gh api octocat - - name: Add test file - run: | - touch test.txt - - name: Commit files - run: | - git add . - git config --local user.email ${{ secrets.APP_ID }}+polusai-auth-helper[bot]@users.noreply.github.com - git config --local user.name "polusai-auth-helper[bot]" - git commit -a -m "Adding test file" - - name: Push changes - uses: ad-m/github-push-action@master - with: - force: true - github_token: ${{ steps.generate_token.outputs.token }} \ No newline at end of file