From b5847cd5714b33f4fc01574eb4787c1fd37b9030 Mon Sep 17 00:00:00 2001 From: Alex Vincent Date: Mon, 29 Apr 2024 04:25:05 +0200 Subject: [PATCH] F2calv/2024 04 ci updates2 (#31) * move rwfs to external repo * revert wf ref --- .github/workflows/build-app.yml | 23 ----- .github/workflows/build-chart.yml | 86 ------------------ .github/workflows/build-image.yml | 142 ------------------------------ .github/workflows/ci.yml | 6 +- 4 files changed, 3 insertions(+), 254 deletions(-) delete mode 100644 .github/workflows/build-app.yml delete mode 100644 .github/workflows/build-chart.yml delete mode 100644 .github/workflows/build-image.yml diff --git a/.github/workflows/build-app.yml b/.github/workflows/build-app.yml deleted file mode 100644 index 25f1d0f..0000000 --- a/.github/workflows/build-app.yml +++ /dev/null @@ -1,23 +0,0 @@ -name: build-app - -on: - workflow_call: - inputs: - fullSemVer: - type: string - description: e.g. 1.2.3-feature-my-feature.12 - required: true - -jobs: - build-app: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - - name: dotnet restore - run: dotnet restore --verbosity minimal --configfile NuGet.config - - - name: dotnet build - run: dotnet build -c Release --nologo --no-restore -p:Version='${{ inputs.fullSemVer }}' -p:SourceRevisionId=${{ github.sha }} - - #TODO: could run dotnet test here, etc... \ No newline at end of file diff --git a/.github/workflows/build-chart.yml b/.github/workflows/build-chart.yml deleted file mode 100644 index 592094e..0000000 --- a/.github/workflows/build-chart.yml +++ /dev/null @@ -1,86 +0,0 @@ -name: build-chart - -on: - workflow_call: - inputs: - semVer: - type: string - description: e.g. 1.2.3-feature-my-feature.12 - required: true - -jobs: - build-chart: - runs-on: ubuntu-latest - permissions: - packages: write #for pushing helm package - env: - REGISTRY: ghcr.io - #CHART_REPOSITORY: Note: set dynamically, i.e. github.repository_owner/charts/IMAGE_NAME - GIT_TAG: ${{ inputs.semVer }} - steps: - - uses: actions/checkout@v4 - - - 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: | - npm install --global json5 - json5 -c .devcontainer/devcontainer.json - HELM_VERSION_TO_INSTALL=$(cat .devcontainer/devcontainer.json | jq -r '.features[] | select(.helm | . != null).helm') - echo "HELM_VERSION_TO_INSTALL=$HELM_VERSION_TO_INSTALL" >> $GITHUB_ENV - echo $HELM_VERSION_TO_INSTALL - - - uses: azure/setup-helm@v4 - 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@v5 - 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 "changed=true" >> $GITHUB_OUTPUT - 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 diff --git a/.github/workflows/build-image.yml b/.github/workflows/build-image.yml deleted file mode 100644 index f96ed4f..0000000 --- a/.github/workflows/build-image.yml +++ /dev/null @@ -1,142 +0,0 @@ -name: build-image - -on: - workflow_call: - inputs: - registry: - type: string - description: e.g. ghcr.io or docker.io - default: ghcr.io - repositoryOverride: - type: string - description: Default repository is the name of the repo, i.e. f2calv/my-repo-name - tag: - type: string - description: e.g. 1.2.3-feature-my-feature.12 - required: true - tagOverride: - type: string - description: Default branch tag override, i.e. tag 1.2.3 -> latest - default: latest - devTagOverride: - type: string - description: Feature branch tag override, i.e. tag 1.2.3-feature-my-feature.12 -> latest-dev - default: latest-dev - platform: - type: string - description: Specify the target platform for the build output, e.g. linux/amd64,linux/arm64,linux/arm/v7 - default: linux/amd64,linux/arm64,linux/arm/v7 - pushOverride: - type: boolean - description: image push happens only on default branch, override by setting true - default: false - outputs: - deployableRepository: - description: Deployable repository name, e.g. lowercase owner/repo-name - value: ${{ jobs.build-image.outputs.deployableRepository }} - deployableTag: - description: Most unique deployable tag, e.g. 1.2.3 or latest-dev - value: ${{ jobs.build-image.outputs.deployableTag }} - -jobs: - build-image: - runs-on: ubuntu-latest - #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 - outputs: - deployableRepository: ${{ steps.setupvars.outputs.deployableRepository }} - deployableTag: ${{ steps.build.outputs.deployableTag }} - steps: - - uses: actions/checkout@v4 - - - name: set vars (1 of 3) - id: setupvars - run: | - REPOSITORY_OVERRIDE=${{ inputs.repositoryOverride }} - - if [ ! -z "$REPOSITORY_OVERRIDE" ]; then - #set the repository to the repositoryOverride & lowercase the input - REPOSITORY=${REPOSITORY_OVERRIDE,,} - - echo "IMAGE_NAME=$REPOSITORY" >> $GITHUB_ENV - else - #set the repository to the current gh repository - REPOSITORY=${{ github.repository }} - #strip the repository_owner away from the repository name to get the image name - IMAGE_NAME=$(echo $REPOSITORY | sed "s|${{ github.repository_owner }}\/||g") - #lowercase the IMAGE_NAME - IMAGE_NAME=${IMAGE_NAME,,} - echo "IMAGE_NAME=$IMAGE_NAME" >> $GITHUB_ENV - - #lowercase the repository var and override the env variable - REPOSITORY=${REPOSITORY,,} - fi - echo "REPOSITORY=$REPOSITORY" >> $GITHUB_ENV - echo "deployableRepository=$REPOSITORY" >> $GITHUB_OUTPUT - - - name: set vars (2 of 3) - if: github.ref != 'refs/heads/main' #feature branch use devTagOverride - run: | - TAG=${{ inputs.devTagOverride }} - if [ ! -z "$TAG" ]; then - TAG=${TAG,,} - else - TAG=${{ inputs.tag }} - TAG=${TAG,,} - fi - echo "TAG=$TAG" >> $GITHUB_ENV - echo "IMAGE_PUSH=${{ inputs.pushOverride }}" >> $GITHUB_ENV - - - name: set vars (3 of 3) - if: github.ref == 'refs/heads/main' #default branch use tagOverride - id: tagging - run: | - TAG=${{ inputs.tag }} - TAG=${TAG,,} - echo "TAG=$TAG" >> $GITHUB_ENV - - OVERRIDE_TAG=${{ inputs.tagOverride }} - OVERRIDE_TAG=${OVERRIDE_TAG,,} - echo "OVERRIDE_TAG=$OVERRIDE_TAG" >> $GITHUB_ENV - echo "IMAGE_PUSH=true" >> $GITHUB_ENV - - - name: docker login ${{ inputs.registry }} - run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ${{ inputs.registry }} -u ${{ github.actor }} --password-stdin - - - name: docker buildx build/push - id: build - run: | - docker buildx create --name multiarchtest --use - - OPT_TAG=() - if [ ! -z "$OVERRIDE_TAG" ]; then - OPT_TAG=(-t "${{ inputs.registry }}/$REPOSITORY:$OVERRIDE_TAG") - echo "deployableTag=$OVERRIDE_TAG" >> $GITHUB_OUTPUT - else - echo "deployableTag=$TAG" >> $GITHUB_OUTPUT - fi - - OPT_PUSH=() - if [ "$IMAGE_PUSH" == "true" ]; then - OPT_PUSH=(--push) - fi - - docker buildx build \ - -t ${{ inputs.registry }}/$REPOSITORY:$TAG \ - "${OPT_TAG[@]}" \ - --label "GITHUB_RUN_ID=${{ github.run_id }}" \ - --label "IMAGE_NAME=$IMAGE_NAME" \ - --label "org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }}" \ - --build-arg GIT_REPO=${{ github.repository }} \ - --build-arg GIT_TAG=${{ inputs.tag }} \ - --build-arg GIT_BRANCH=${{ github.ref }} \ - --build-arg GIT_COMMIT=${{ github.sha }} \ - --build-arg GITHUB_WORKFLOW=${{ github.workflow }} \ - --build-arg GITHUB_RUN_ID=${{ github.run_id }} \ - --build-arg GITHUB_RUN_NUMBER=${{ github.run_number }} \ - --platform ${{ inputs.platform }} \ - --pull \ - "${OPT_PUSH[@]}" \ - . \ No newline at end of file diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5b97db2..af99582 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -26,19 +26,19 @@ jobs: tag-and-release: false app: - uses: ./.github/workflows/build-app.yml + uses: f2calv/gha-workflows/.github/workflows/app-build-dotnet.yml@v1 needs: versioning with: fullSemVer: ${{ needs.versioning.outputs.fullSemVer }} image: - uses: ./.github/workflows/build-image.yml + uses: f2calv/gha-workflows/.github/workflows/container-image-build.yml@v1 needs: [versioning, app] with: tag: ${{ needs.versioning.outputs.semVer }} chart: - uses: ./.github/workflows/build-chart.yml + uses: f2calv/gha-workflows/.github/workflows/helm-chart-build.yml@v1 needs: [versioning, app, image] if: github.ref == 'refs/heads/main' with: