Skip to content

Change pull_request_target to pull_request in workflow #312

Change pull_request_target to pull_request in workflow

Change pull_request_target to pull_request in workflow #312

Workflow file for this run

# Copyright 2025 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
---
name: Build and Run Apigee Migration Assessment Image
on: # yamllint disable-line rule:truthy
push:
branches:
- main
paths-ignore:
- '**.md'
pull_request:
paths-ignore:
- '**.md'
branches:
- main
types:
- opened
- synchronize
- reopened
workflow_dispatch:
permissions: read-all
env:
REGISTRY: ghcr.io
IMAGE_NAME: ghcr.io/${{ github.repository }}/apigee-migration-assessment-tool
jobs:
unittest:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v5
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install -r test-requirements.txt
- name: Run unittests
run: python -m unittest discover tests -v
build-and-push:
runs-on: ubuntu-latest
needs: unittest
permissions:
contents: read
packages: write
outputs:
image_tag: ${{ steps.get_tag.outputs.tag }}
steps:
- name: Checkout repository
uses: actions/checkout@v5
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Log into registry ${{ env.REGISTRY }}
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.IMAGE_NAME }}
tags: |
type=raw,value=latest,enable={{is_default_branch}}
type=ref,event=branch
type=ref,event=pr
type=sha
- name: Determine primary image tag
id: get_tag
run: |
if [[ "${{ github.event_name }}" == "pull_request_target" ]]; then
echo "tag=pr-${{ github.event.number }}" >> "$GITHUB_OUTPUT"
elif [[ "${GITHUB_REF}" == "refs/heads/main" ]]; then
echo "tag=latest" >> "$GITHUB_OUTPUT"
else
# For feature branches, etc.
echo "tag=${GITHUB_REF_NAME}" | sed 's/\//-/g' >> "$GITHUB_OUTPUT"
fi
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
test-opdk:
runs-on: ubuntu-latest
needs:
- build-and-push
permissions:
id-token: write
contents: read
steps:
- name: Checkout repository
uses: actions/checkout@v5
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.10'
- name: Install dependencies
run: pip install requests pyotp
- name: Generate Apigee Token
id: get_token
env:
APIGEE_EDGE_USER: ${{ secrets.APIGEE_EDGE_USER }}
APIGEE_EDGE_PASSWORD: ${{ secrets.APIGEE_EDGE_PASSWORD }}
OTP_SECRET: ${{ secrets.APIGEE_EDGE_OTP_SECRET }}
run: python tests/ci/generate_apigee_edge_access_token.py
- name: Fetch input.properties
run: |
echo "${{ secrets.APIGEE_EDGE_INPUT_PROPERTIES }}" | base64 -d > "${{ github.workspace }}/input.properties"
- name: Run tests on Apigee Edge SAAS.
run: |
mkdir ${{ github.workspace }}/output
sudo chmod 777 ${{ github.workspace }}/output
docker run \
-v "${{ github.workspace }}/input.properties:/app/input.properties" \
-v "${{ github.workspace }}/output:/app/target" \
-e "SOURCE_AUTH_TOKEN=${STEPS_GET_TOKEN_OUTPUTS_ACCESS_TOKEN}" \
"${IMAGE_NAME}:${NEEDS_BUILD_AND_PUSH_OUTPUTS_IMAGE_TAG}" \
--skip-target-validation \
--resources all
env:
STEPS_GET_TOKEN_OUTPUTS_ACCESS_TOKEN: ${{ steps.get_token.outputs.access_token }}
NEEDS_BUILD_AND_PUSH_OUTPUTS_IMAGE_TAG: ${{ needs.build-and-push.outputs.image_tag }}
- name: Upload latest assement results
uses: actions/upload-artifact@v4
with:
name: assessment-report
path: "${{ github.workspace }}/output/qualification_report.xlsx"