Upgrade 16 (#58) #7
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
name: Build and Deploy | |
env: | |
REGISTRY: ghcr.io | |
REPOSITORY_NAME: developer-experience/developer-portal | |
LICENSE_PLATE: f5ff48 | |
TARGET_FILE: 'values.dev.yaml' | |
WORKING_DIR: 'developer-portal' | |
YAML_PROPERTY_PATH: '.janus.upstream.backstage.image.tag' | |
on: | |
push: | |
paths-ignore: | |
- '.github/**' | |
- 'README.md' | |
branches: [ "main" ] | |
pull_request: | |
types: [opened, synchronize, reopened, labeled] | |
branches: [ "main" ] | |
jobs: | |
build: | |
if: github.event_name == 'push' || (github.event_name == 'pull_request' && contains(github.event.pull_request.labels.*.name, 'build')) | |
runs-on: ubuntu-latest | |
steps: | |
- name: Delete unnecessary files | |
run: | | |
sudo rm -rf /usr/share/dotnet | |
sudo rm -rf /opt/ghc | |
sudo rm -rf "/usr/local/share/boost" | |
sudo rm -rf "$AGENT_TOOLSDIRECTORY" | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- name: Docker meta | |
id: meta | |
uses: docker/metadata-action@v4 | |
with: | |
images: ghcr.io/${{ github.repository_owner }}/${{ env.REPOSITORY_NAME }} | |
# Always generate latest tag (https://github.com/docker/metadata-action#latest-tag) | |
flavor: latest=true | |
# Sha tag is used in udpate_deploy_file job below | |
tags: | | |
type=sha | |
type=ref,event=pr | |
- name: Login to GHCR | |
uses: docker/login-action@v2 | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ github.repository_owner }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- | |
# Support for multiplatform build. Using for dev debugging | |
name: Set up QEMU | |
uses: docker/setup-qemu-action@v2 | |
- # Support for multiplatform build. Using for dev debugging | |
name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
- name: Build container | |
uses: docker/build-push-action@v4 | |
with: | |
context: . | |
file: packages/backend/Dockerfile | |
push: true | |
platforms: linux/amd64,linux/arm64 | |
tags: ${{ steps.meta.outputs.tags }} | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
udpate_deploy_file: | |
if: github.event_name == 'push' | |
runs-on: ubuntu-latest | |
needs: build | |
steps: | |
- name: Setup deploy repo access | |
uses: webfactory/[email protected] | |
with: | |
ssh-private-key: ${{ secrets.MANIFEST_REPO_DEPLOY_KEY }} | |
- name: Checkout CD repo | |
uses: actions/checkout@v3 | |
with: | |
ssh-key: ${{ secrets.MANIFEST_REPO_DEPLOY_KEY }} | |
repository: ${{ secrets.MANIFEST_REPO }} | |
# This assumes that sha was used as a tag in the above job | |
# See https://github.com/docker/metadata-action/issues/164 for discussion about the list | |
# of tags returned from metadata-action and using github.sha | |
- name: Get short sha | |
run: echo "GITHUB_SHA_SHORT="sha-"$(echo ${{ github.sha }} | cut -c -7)" >> $GITHUB_ENV | |
- name: Update image tag | |
run: | | |
cd ${{ env.WORKING_DIR }} | |
yq -i '${{ env.YAML_PROPERTY_PATH }} = "${{ env.GITHUB_SHA_SHORT }}"' ${{ env.TARGET_FILE }} | |
- name: Commit and push update | |
run: | | |
git config --local user.email "[email protected]" | |
git config --local user.name "GitHub Action" | |
git commit -am "Update image tag for dev" | |
git push origin | |