Skip to content

Ci: Add GitHub Actions CI/CD pipeline. #13

Ci: Add GitHub Actions CI/CD pipeline.

Ci: Add GitHub Actions CI/CD pipeline. #13

Workflow file for this run

name: CI
permissions:
id-token: write # Required for signing
contents: read
packages: write
attestations: write
pages: write
on:
push:
branches:
- master
pull_request:
branches:
- master
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
env:
IMAGE: ghcr.io/twogiants/console-functions-plugin
jobs:
# --------
# CHECKS
# --------
checks:
name: Lint and Test
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "22"
cache: yarn
- name: Enable Corepack
run: corepack enable
- name: Install Dependencies
run: yarn install --immutable
- name: Lint
run: yarn lint
- name: Test
run: yarn test
# -----------
# BUILD IMAGE
# -----------
build-image:
name: Build Image
needs: checks
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v4
- uses: docker/setup-qemu-action@v3
- uses: docker/setup-buildx-action@v3
- name: Build Image
uses: docker/build-push-action@v6
env:
SOURCE_DATE_EPOCH: 0
with:
context: .
push: false
# Multi-arch is required for OCP.
platforms: linux/amd64,linux/arm64,linux/ppc64le,linux/s390x
cache-from: type=gha
cache-to: type=gha,mode=max
# -------------
# PUBLISH IMAGE
# -------------
publish:
name: Publish Image
needs: build-image
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
runs-on: ubuntu-latest
timeout-minutes: 30
outputs:
digest: ${{ steps.build-and-push.outputs.digest }}
steps:
- uses: actions/checkout@v4
- uses: docker/setup-qemu-action@v3
- uses: docker/setup-buildx-action@v3
- name: Login to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and Push Image
id: build-and-push
uses: docker/build-push-action@v6
env:
SOURCE_DATE_EPOCH: 0
with:
context: .
push: true
platforms: linux/amd64,linux/arm64,linux/ppc64le,linux/s390x
tags: |
${{ env.IMAGE }}:latest
${{ env.IMAGE }}:sha-${{ github.sha }}
cache-from: type=gha
annotations: |
index:org.opencontainers.image.description=Serverless Functions Console Plugin for OpenShift
index:org.opencontainers.image.source=https://github.com/twoGiants/func-console
index:org.opencontainers.image.vendor=https://github.com/twoGiants/func-console
index:org.opencontainers.image.url=https://github.com/twoGiants/func-console/pkgs/container/console-functions-plugin
# Attestation is required for OCP.
- name: Attest Build Provenance
uses: actions/attest-build-provenance@v3
with:
subject-name: ${{ env.IMAGE }}
subject-digest: ${{ steps.build-and-push.outputs.digest }}
push-to-registry: true
# ------------
# DEPLOY PAGES
# ------------
deploy-pages:
name: Deploy Pages
needs: publish
runs-on: ubuntu-latest
timeout-minutes: 5
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- uses: actions/checkout@v4
- name: Setup Helm
uses: azure/setup-helm@v4
- name: Generate deployment YAML
run: |
mkdir public
helm template console-functions-plugin charts/openshift-console-plugin \
-n console-functions-plugin \
--set "plugin.image=${{ env.IMAGE }}:sha-${{ github.sha }}@${{ needs.publish.outputs.digest }}" \
> public/plugin.yaml
- name: Upload Pages artifact
uses: actions/upload-pages-artifact@v3
with:
path: ./public
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v5