Skip to content

fix ci

fix ci #80

Workflow file for this run

name: ci
on:
workflow_dispatch:
push:
branches-ignore:
- "preview/**"
paths-ignore:
# - .github
# - .scripts
# - .charts
- kustomize
- LICENSE
- README.md
- build.sh
- build.ps1
pull_request:
branches: [main]
types: [opened, synchronize, reopened]
jobs:
build_app:
runs-on: ubuntu-latest
outputs:
semVer: ${{ steps.gitversion.outputs.semVer }}
fullSemVer: ${{ steps.gitversion.outputs.fullSemVer }}
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: .NET 7.x SDK
uses: actions/setup-dotnet@v3
with:
dotnet-version: 7.0.x
- name: gitversion (1 of 2)
uses: gittools/actions/gitversion/setup@v0
with:
versionSpec: 5.x
- name: gitversion (2 of 2)
id: gitversion
uses: gittools/actions/gitversion/execute@v0
with:
useConfigFile: true
additionalArguments: /nofetch
- name: dotnet restore
run: dotnet restore --verbosity minimal --configfile NuGet.config
- name: dotnet build
run: dotnet build -c Release --nologo --no-restore -p:Version='${{ steps.gitversion.outputs.fullSemVer }}' -p:SourceRevisionId=${{ github.sha }}
#TODO: could run dotnet test here, etc...
build_image:
runs-on: ubuntu-latest
needs: build_app
#https://github.blog/changelog/2021-04-20-github-actions-control-permissions-for-github_token/
#https://docs.github.com/en/actions/using-jobs/assigning-permissions-to-jobs
permissions:
packages: write #for pushing container image
env:
REGISTRY: ghcr.io
REPOSITORY: ${{ github.repository }}
GIT_REPO: ${{ github.repository }}
GIT_TAG: ${{ needs.build_app.outputs.semVer }}
GIT_BRANCH: ${{ github.ref }}
GIT_COMMIT: ${{ github.sha }}
steps:
- uses: actions/checkout@v3
# with:
# fetch-depth: 0
- name: set vars (1 of 2)
run: |
IMAGE_NAME=$(echo $REPOSITORY | sed "s|${{ github.repository_owner }}\/||g")
echo "IMAGE_NAME=$IMAGE_NAME" >> $GITHUB_ENV
- name: set vars (2 of 2)
if: github.ref != 'refs/heads/main' #non-default branch use a simplistic SemVer
run: echo "GIT_TAG=dev" >> $GITHUB_ENV
- name: docker login ${{ env.REGISTRY }}
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login $REGISTRY -u ${{ github.actor }} --password-stdin
- name: docker buildx build/push
if: github.ref == 'refs/heads/main'
run: |
docker buildx create --name multiarchtest --use
docker buildx build \
-t $REGISTRY/$REPOSITORY:$GIT_TAG \
-t $REGISTRY/$REPOSITORY:latest \
--label "GITHUB_RUN_ID=${{ github.run_id }}" \
--label "IMAGE_NAME=$IMAGE_NAME" \
--build-arg GIT_REPO=$GIT_REPO \
--build-arg GIT_TAG=$GIT_TAG \
--build-arg GIT_BRANCH=$GIT_BRANCH \
--build-arg GIT_COMMIT=$GIT_COMMIT \
--build-arg GITHUB_WORKFLOW=${{ github.workflow }} \
--build-arg GITHUB_RUN_ID=${{ github.run_id }} \
--build-arg GITHUB_RUN_NUMBER=${{ github.run_number }} \
--platform linux/amd64,linux/arm64,linux/arm/v7 \
--pull \
--push \
.
- name: docker buildx build/push (dev)
if: github.ref != 'refs/heads/main'
run: |
docker buildx create --name multiarchtest --use
docker buildx build \
-t $REGISTRY/$REPOSITORY:$GIT_TAG \
--label "GITHUB_RUN_ID=${{ github.run_id }}" \
--label "IMAGE_NAME=$IMAGE_NAME" \
--build-arg GIT_REPO=$GIT_REPO \
--build-arg GIT_TAG=$GIT_TAG \
--build-arg GIT_BRANCH=$GIT_BRANCH \
--build-arg GIT_COMMIT=$GIT_COMMIT \
--build-arg GITHUB_WORKFLOW=${{ github.workflow }} \
--build-arg GITHUB_RUN_ID=${{ github.run_id }} \
--build-arg GITHUB_RUN_NUMBER=${{ github.run_number }} \
--platform linux/amd64,linux/arm64,linux/arm/v7 \
--pull \
--push \
.
push_chart:
runs-on: ubuntu-latest
needs: [build_app, build_image]
if: github.ref == 'refs/heads/main'
permissions:
packages: write #for pushing helm package
contents: write #for creating releases/tags
env:
REGISTRY: ghcr.io
#CHART_REPOSITORY: Note: set dynamically, i.e. github.repository_owner/charts/IMAGE_NAME
GIT_TAG: ${{ needs.build_app.outputs.semVer }}
HELM_EXPERIMENTAL_OCI: 1
HELM_VERSION_TO_INSTALL: 3.9.2 #Note: keep this version in sync inside the devcontainer
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0 #Note: shallow clone may break git tag & ct lint...
- name: set vars (1 of 3)
run: |
IMAGE_NAME=$(echo $REPOSITORY | sed "s|$USERNAME\/||g")
echo "IMAGE_NAME=$IMAGE_NAME" >> $GITHUB_ENV
- name: set vars (2 of 3)
run: echo "CHART_REPOSITORY=${{ github.repository_owner }}/charts/$IMAGE_NAME" >> $GITHUB_ENV
- name: set vars (3 of 3) #pulls helm version from devcontainer
run: |
HELM_VERSION_TO_INSTALL=$(cat .devcontainer/devcontainer.json | jq -r '.features."kubectl-helm-minikube".helm')
echo "HELM_VERSION_TO_INSTALL=$HELM_VERSION_TO_INSTALL" >> $GITHUB_ENV
- name: install helm
uses: azure/setup-helm@v3
with:
version: ${{ env.HELM_VERSION_TO_INSTALL }}
- name: helm registry login
run: |
echo ${{ secrets.GITHUB_TOKEN }} | helm registry login ${REGISTRY}/${CHART_REPOSITORY} --username ${{ github.repository_owner }} --password-stdin
- uses: actions/setup-python@v4
with:
python-version: 3.7
if: false #not implemented/working yet
- name: chart-testing (setup)
uses: helm/chart-testing-action@v2
if: false #not implemented/working yet
- name: chart-testing (run list-changed)
id: list-changed
run: |
changed=$(ct list-changed --target-branch main)
if [[ -n "$changed" ]]; then
echo "::set-output name=changed::true"
fi
if: false #not implemented/working yet
- name: chart-testing (run lint)
run: ct lint
if: false #not implemented/working yet
- name: create kind cluster
uses: helm/kind-action@v1
#if: steps.list-changed.outputs.changed == 'true'
if: false #not implemented/working yet
- name: chart-testing (run install)
run: ct install
if: false #not implemented/working yet
- name: helm package
run: |
helm package ${{ github.workspace }}/charts/$IMAGE_NAME/ --destination ${{ github.workspace }}/artifacts/ --app-version ${{ env.GIT_TAG }}
if: false #not implemented/working yet
- name: helm push
run: |
helm push ${{ github.workspace }}/artifacts/$IMAGE_NAME-0.1.0.tgz oci://ghcr.io/${{ github.repository_owner }}
if: false #not implemented/working yet, need to change the chart version in filename
release:
needs: [build_app, build_image, push_chart]
if: github.ref == 'refs/heads/main'
uses: f2calv/gha-workflows/.github/workflows/gha-release-versioning.yml@v1
with:
tag-prefix: ''
move-major-tag: false