From 795061897eb3b3c8961e5f8497682319b4c48470 Mon Sep 17 00:00:00 2001 From: Thomas Cooper Date: Fri, 25 Oct 2024 17:17:17 -0400 Subject: [PATCH] moving to our actions --- .github/workflows/add-labels-main.yml | 23 ----- .github/workflows/backport.yml | 42 --------- .github/workflows/build-package-publish.yml | 89 +++++++++++++++++++ .github/workflows/label-community-issues.yml | 29 ------ .../scripts/label_community_issues.py | 36 -------- 5 files changed, 89 insertions(+), 130 deletions(-) delete mode 100644 .github/workflows/add-labels-main.yml delete mode 100644 .github/workflows/backport.yml create mode 100644 .github/workflows/build-package-publish.yml delete mode 100644 .github/workflows/label-community-issues.yml delete mode 100644 .github/workflows/scripts/label_community_issues.py diff --git a/.github/workflows/add-labels-main.yml b/.github/workflows/add-labels-main.yml deleted file mode 100644 index 290bff105..000000000 --- a/.github/workflows/add-labels-main.yml +++ /dev/null @@ -1,23 +0,0 @@ -name: Force backport labels for main - -on: - pull_request_target: - branches: - - main - types: - - opened - -jobs: - add_labels: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - id: version - uses: juliangruber/read-file-action@ebfa650188272343fef925480eb4d18c5d49b925 - with: - path: ./connectors/VERSION - - uses: actions-ecosystem/action-add-labels@v1 - with: - labels: | - auto-backport - v${{ steps.version.outputs.content }} diff --git a/.github/workflows/backport.yml b/.github/workflows/backport.yml deleted file mode 100644 index 102bf7183..000000000 --- a/.github/workflows/backport.yml +++ /dev/null @@ -1,42 +0,0 @@ -name: Backport PR - -on: - pull_request_target: - branches: - - main - types: - - labeled - - closed - -jobs: - backport: - if: | - github.event.pull_request.merged == true - && contains(github.event.pull_request.labels.*.name, 'auto-backport') - && ( - (github.event.action == 'labeled' && github.event.label.name == 'auto-backport') - || (github.event.action == 'closed') - ) - runs-on: ubuntu-latest - steps: - - name: Checkout Actions - uses: actions/checkout@v2 - with: - repository: 'swiftype/kibana-github-actions' - ref: main - path: ./actions - - - name: Install Actions - run: npm install --production --prefix ./actions - - - name: Run Backport - uses: ./actions/backport - with: - github_token: ${{ secrets.GITHUB_TOKEN }} - approver_token: ${{ secrets.REPO_SCOPED_TOKEN }} - auto_approve: 'true' - commit_user: elastic - commit_email: ent-search-backport@users.noreply.github.com - auto_merge: 'true' - auto_merge_method: 'squash' - manual_backport_command_template: 'backport --pr %pullNumber% --autoMerge --autoMergeMethod squash' diff --git a/.github/workflows/build-package-publish.yml b/.github/workflows/build-package-publish.yml new file mode 100644 index 000000000..0e5d24ce3 --- /dev/null +++ b/.github/workflows/build-package-publish.yml @@ -0,0 +1,89 @@ +name: Build, Test, Package, and Publish + +# AI Chat Ad Server application CI/CD pipeline +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + release: + types: [published] + +env: + REGISTRY: ghcr.io + IMAGE_NAME: expedient/elastic-connectors + +jobs: + build-and-test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Set up Python 3.10 + uses: actions/setup-python@v4 + with: + python-version: "3.10" + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -e . + pip install -r requirements/tests.txt + - name: Run unit tests + run: | + python -m unittest discover tests + - name: Build application + run: | + echo "Building application..." + # Add any additional build steps here if needed + + build-and-push-image: + needs: build-and-test + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + id-token: write + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Install cosign + if: github.event_name != 'pull_request' + uses: sigstore/cosign-installer@v3.3.0 + with: + cosign-release: 'v2.2.2' + + - name: Setup Docker buildx + uses: docker/setup-buildx-action@v2 + + - name: Log into registry ${{ env.REGISTRY }} + if: github.event_name != 'pull_request' + uses: docker/login-action@v2 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract Docker metadata + id: meta + uses: docker/metadata-action@v4 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + + - name: Build and push Docker image + id: build-and-push + uses: docker/build-push-action@v4 + with: + context: . + file: ./Dockerfile + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max + + - name: Sign the published Docker image + if: ${{ github.event_name != 'pull_request' }} + env: + COSIGN_EXPERIMENTAL: "true" + run: echo "${{ steps.meta.outputs.tags }}" | xargs -I {} cosign sign {}@${{ steps.build-and-push.outputs.digest }} \ No newline at end of file diff --git a/.github/workflows/label-community-issues.yml b/.github/workflows/label-community-issues.yml deleted file mode 100644 index 303bb4491..000000000 --- a/.github/workflows/label-community-issues.yml +++ /dev/null @@ -1,29 +0,0 @@ -name: Label Community Issues - -on: - issues: - types: [opened] - -jobs: - run-python-script: - runs-on: ubuntu-latest - - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - - name: Set up Python - uses: actions/setup-python@v5 - with: - python-version: '3.10' - - - name: Install dependencies - run: python3 -m pip install aiohttp gidgethub - - - name: Run Python script - run: python .github/workflows/scripts/label_community_issues.py - env: - ACTOR: ${{ github.actor }} - NUMBER: ${{ github.event.issue.number }} - REPO: ${{ github.repository }} - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/scripts/label_community_issues.py b/.github/workflows/scripts/label_community_issues.py deleted file mode 100644 index 18e8cee30..000000000 --- a/.github/workflows/scripts/label_community_issues.py +++ /dev/null @@ -1,36 +0,0 @@ -#!/usr/bin/env python - -import aiohttp -import asyncio -import os -from gidgethub.aiohttp import GitHubAPI -from gidgethub import BadRequest - -ACTOR = os.getenv("ACTOR") -NUMBER = os.getenv("NUMBER") -REPO = os.getenv("REPO") -GITHUB_TOKEN = os.getenv("GITHUB_TOKEN") - -LABELS = ["community-driven", "needs-triage"] - -async def main(): - async with aiohttp.ClientSession() as session: - gh = GitHubAPI(session, requester="", base_url="https://api.github.com", oauth_token=GITHUB_TOKEN) - - print("********") - print(f"ACTOR: {ACTOR}") - print(f"NUMBER: {NUMBER}") - print(f"REPO: {REPO}") - print("********") - - try: - # this API returns a None response, but will raise if the user isn't a collaborator - await gh.getitem(f"/repos/{REPO}/collaborators/{ACTOR}") - print("User is a collaborator, not applying labels.") - except BadRequest as e: - # if this fails we want it to be noisy, so no try/except - print("User is not a collaborator, applying labels...") - await gh.post(f"/repos/{REPO}/issues/{NUMBER}/labels", data={"labels": LABELS}) - -if __name__ == "__main__": - asyncio.run(main())