diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..698fbc9 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,31 @@ +name: Build + +on: + push: + branches: + - main + # XXX: remove before merging + pull_request: + +env: + DOCKERHUB_REPO: mozillaconduit/git-hg-sync + DOCKER_USER: ${{ vars.DOCKERHUB_USERNAME }} + DOCKER_PASS: ${{ secrets.DOCKERHUB_TOKEN }} + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ vars.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - name: Build the Docker image + run: docker build -t git-hg-sync . + - name: Tag the image + run: | + [[ -n "$DOCKERHUB_REPO" && -n "$DOCKER_USER" && -n "$DOCKER_PASS" ]] || exit 0 + docker tag "$DOCKERHUB_REPO" "$DOCKERHUB_REPO:${{ github.sha }}" + docker push "$DOCKERHUB_REPO:${{ github.sha }}" diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..a234282 --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,54 @@ +name: Deployment + +on: + push: + branches: + - develop + - staging + - main + release: + types: + - published + # XXX: remove before merging + pull_request: + +env: + IMAGE_NAME: git-hg-sync + GAR_LOCATION: us + GCP_PROJECT_ID: moz-fx-git-hg-sync-prod + GAR_REPOSITORY: git-hg-sync-prod + +jobs: + deploy: + runs-on: ubuntu-latest + environment: build + permissions: + contents: read + id-token: write + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: "0" + - uses: docker/setup-buildx-action@v2 + - id: gcp-auth + name: Google authentication + uses: google-github-actions/auth@v2 + with: + token_format: "access_token" + service_account: artifact-writer@${{ env.GCP_PROJECT_ID }}.iam.gserviceaccount.com + workload_identity_provider: ${{ vars.GCPV2_GITHUB_WORKLOAD_IDENTITY_PROVIDER }} + - name: Log in to the container registry + uses: docker/login-action@v2 + with: + registry: ${{ env.GAR_LOCATION }}-docker.pkg.dev + username: oauth2accesstoken + password: ${{ steps.gcp-auth.outputs.access_token }} + - name: Build and push image + uses: docker/build-push-action@v3 + with: + context: . + tags: | + ${{ env.GAR_LOCATION }}-docker.pkg.dev/${{ env.GCP_PROJECT_ID }}/${{ env.GAR_REPOSITORY }}/${{ env.IMAGE_NAME }}:develop + push: true + cache-from: type=gha + cache-to: type=gha,mode=max diff --git a/.github/workflows/docker_compose.yml b/.github/workflows/docker_compose.yml index 42fba32..3f810f1 100644 --- a/.github/workflows/docker_compose.yml +++ b/.github/workflows/docker_compose.yml @@ -1,4 +1,4 @@ -name: Pytest in docker compose +name: Tests in docker compose on: pull_request: @@ -17,11 +17,11 @@ jobs: mkdir tests_output chmod a+w tests_output - - name: Run docker-compose + - name: Setup docker-compose uses: hoverkraft-tech/compose-action@v2.0.1 with: compose-file: "docker-compose.yaml" - name: Execute tests in the running services run: | - docker compose run test + docker compose run test diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index a09a79a..9bba37b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,4 +1,4 @@ -name: Python +name: Tests on: pull_request: @@ -10,11 +10,11 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - name: Set up Python 3.10 + - name: Setup Python uses: actions/setup-python@v5 with: - python-version: '3.11' - cache: 'pip' + python-version: "3.11" + cache: "pip" - name: Install dependencies run: | python -m pip install --upgrade pip pytest pytest-mock @@ -23,4 +23,4 @@ jobs: echo "${{ github.workspace }}" >> $GITHUB_PATH - name: Test with pytest run: | - pytest --junitxml=pytest.xml + pytest --junitxml=pytest.xml