This repository has been archived by the owner on Aug 19, 2024. It is now read-only.
no-op to test https://github.com/janus-idp/operator/issues/73 - should require auth before running PR check #73
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Copyright 2023 The Janus IDP Authors | |
# | |
# 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: PR Build operator, bundle, and catalog images | |
on: | |
# /!\ Warning: using the pull_request_target event to be able to read secrets. But using this event without the cautionary measures described below | |
# may allow unauthorized GitHub users to open a “pwn request” and exfiltrate secrets. | |
# As recommended in https://iterative.ai/blog/testing-external-contributions-using-github-actions-secrets, | |
# we are adding an 'authorize' job that checks if the workflow was triggered from a fork PR. In that case, the "external" environment | |
# will prevent the job from running until it's approved manually by human intervention. | |
pull_request_target: | |
types: [opened, synchronize, reopened, ready_for_review, closed] | |
branches: [ main ] | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.event.number || github.event.pull_request.head.ref }} | |
cancel-in-progress: true | |
env: | |
REGISTRY: quay.io | |
jobs: | |
authorize: | |
# The 'external' environment is configured with the odo-maintainers team as required reviewers. | |
# All the subsequent jobs in this workflow 'need' this job, which will require manual approval for PRs coming from external forks. | |
# see list of approvers in OWNERS file | |
environment: | |
${{ (github.event.pull_request.head.repo.full_name == github.repository || | |
contains(fromJSON('["gazarenkov","jianrongzhang89","kadel","nickboldt","rm3l"]'), github.actor)) && 'internal' || 'external' }} | |
runs-on: ubuntu-latest | |
steps: | |
- name: approved | |
run: | | |
echo "✓" | |
pr-docker-build: | |
name: PR Docker Build | |
runs-on: ubuntu-latest | |
needs: authorize | |
permissions: | |
contents: read | |
packages: write | |
pull-requests: write | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
ref: ${{ github.event.pull_request.head.ref }} | |
repository: ${{ github.event.pull_request.head.repo.full_name }} | |
- name: Setup Go | |
uses: actions/setup-go@v4 | |
with: | |
go-version-file: 'go.mod' | |
- name: Get the last commit short SHA of the PR | |
run: | | |
SHORT_SHA=$(git rev-parse --short ${{ github.event.pull_request.head.sha }}) | |
echo "SHORT_SHA=$SHORT_SHA" >> $GITHUB_ENV | |
- name: Build and Push operator image | |
uses: ./.github/actions/docker-build | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ secrets.JANUS_QUAY_USERNAME }} | |
password: ${{ secrets.JANUS_QUAY_TOKEN }} | |
# TODO use janus-idp/operator* images instead of janus/operator*; switch to organization-level secrets | |
# username: ${{ vars.QUAY_USERNAME }} | |
# password: ${{ secrets.QUAY_TOKEN }} | |
# imageName: ${{ github.repository }} | |
imageName: janus/operator | |
imageTags: | | |
type=ref,prefix=pr-,event=pr | |
type=ref,prefix=pr-,suffix=-${{ env.SHORT_SHA }},event=pr | |
imageLabels: quay.expires-after=14d | |
push: true | |
dockerfile: docker/Dockerfile | |
- name: Adjust operator image and tag in CSV | |
run: | | |
sed -r -e "s#(image: +)quay.io/.+operator.+#\1quay.io/janus/operator:pr-${{ github.event.number }}-${{ env.SHORT_SHA }}#g" -i bundle/manifests/backstage-operator.clusterserviceversion.yaml | |
echo "Operator in CSV changed to: quay.io/janus/operator:pr-${{ github.event.number }}-${{ env.SHORT_SHA }}" | |
- name: Build and Push operator-bundle image | |
uses: ./.github/actions/docker-build | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ secrets.JANUS_QUAY_USERNAME }} | |
password: ${{ secrets.JANUS_QUAY_TOKEN }} | |
# TODO use janus-idp/operator* images instead of janus/operator*; switch to organization-level secrets | |
# username: ${{ vars.QUAY_USERNAME }} | |
# password: ${{ secrets.QUAY_TOKEN }} | |
# imageName: ${{ github.repository }}-bundle | |
imageName: janus/operator-bundle | |
imageTags: | | |
type=ref,prefix=pr-,event=pr | |
type=ref,prefix=pr-,suffix=-${{ env.SHORT_SHA }},event=pr | |
imageLabels: quay.expires-after=14d | |
push: true | |
dockerfile: docker/bundle.Dockerfile | |
- name: Generate operator-catalog dockerfile | |
run: | | |
set -ex | |
OS=$(go env GOOS) && ARCH=$(go env GOARCH) && \ | |
curl -sSLo /tmp/opm https://github.com/operator-framework/operator-registry/releases/download/v1.33.0/${OS}-${ARCH}-opm && chmod +x /tmp/opm | |
/tmp/opm index add --container-tool docker --mode semver \ | |
--tag operator-catalog:pr-${{ github.event.number }}-${{ env.SHORT_SHA }} \ | |
--bundles quay.io/janus/operator-bundle:pr-${{ github.event.number }}-${{ env.SHORT_SHA }} --generate | |
- name: Build and Push operator-catalog image | |
uses: ./.github/actions/docker-build | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ secrets.JANUS_QUAY_USERNAME }} | |
password: ${{ secrets.JANUS_QUAY_TOKEN }} | |
# TODO use janus-idp/operator* images instead of janus/operator*; switch to organization-level secrets | |
# username: ${{ vars.QUAY_USERNAME }} | |
# password: ${{ secrets.QUAY_TOKEN }} | |
# imageName: ${{ github.repository }}-catalog | |
imageName: janus/operator-catalog | |
imageTags: | | |
type=ref,prefix=pr-,event=pr | |
type=ref,prefix=pr-,suffix=-${{ env.SHORT_SHA }},event=pr | |
imageLabels: quay.expires-after=14d | |
push: true | |
dockerfile: index.Dockerfile | |
- name: Comment image links in PR | |
uses: actions/github-script@v6 | |
with: | |
# TODO use janus-idp/operator* images instead of janus/operator* | |
script: | | |
github.rest.issues.createComment({ | |
issue_number: context.issue.number, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
body: 'PR images are available:<br/><ol><li>https://quay.io/janus/operator:pr-${{ github.event.number }}-${{ env.SHORT_SHA }}</li><li>https://quay.io/janus/operator-bundle:pr-${{ github.event.number }}-${{ env.SHORT_SHA }}</li><li>https://quay.io/janus/operator-catalog:pr-${{ github.event.number }}-${{ env.SHORT_SHA }}</li></ol>' | |
}) |