Skip to content

0.0.12-pre

0.0.12-pre #14

Workflow file for this run

# SPDX-License-Identifier: Apache-2.0
# Licensed to the Ed-Fi Alliance under one or more agreements.
# The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0.
# See the LICENSE and NOTICES files in the project root for more information.
name: On Pre-Release
on:
release:
types:
- prereleased
workflow_dispatch:
permissions: read-all
env:
ARTIFACTS_API_KEY: ${{ secrets.AZURE_ARTIFACTS_PERSONAL_ACCESS_TOKEN }}
ARTIFACTS_FEED_URL: "https://pkgs.dev.azure.com/ed-fi-alliance/Ed-Fi-Alliance-OSS/_packaging/EdFi/nuget/v3/index.json"
VSS_NUGET_EXTERNAL_FEED_ENDPOINTS: '{"endpointCredentials": [{"endpoint": "https://pkgs.dev.azure.com/ed-fi-alliance/Ed-Fi-Alliance-OSS/_packaging/EdFi/nuget/v3/index.json","password": "${{ secrets.AZURE_ARTIFACTS_PERSONAL_ACCESS_TOKEN }}"}]}'
DOCKER_HUB_TOKEN: ${{ secrets.DOCKER_HUB_TOKEN }}
DOCKER_USERNAME: ${{ vars.DOCKER_USERNAME }}
MANIFEST_FILE: "_manifest/spdx_2.2/manifest.spdx.json"
PACKAGE_NAME: "AdminConsole.InstanceManagementWorker"
REF: ${{ github.ref_name }}
IMAGE_NAME: ${{ vars.IMAGE_NAME }}
jobs:
pack:
name: Build and Pack
runs-on: ubuntu-22.04
defaults:
run:
shell: pwsh
outputs:
hash-code: ${{ steps.hash-code.outputs.hash-code }}
instance-management-version: ${{ steps.versions.outputs.instance-management }}
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
fetch-depth: 0
- name: Set Version Numbers
id: versions
run: |
$prefix = "v"
# Install the MinVer CLI tool
&dotnet tool install --global minver-cli
$appVersion = $(minver -t $prefix)
# Full release name
"instance-management=$appVersion" >> $env:GITHUB_OUTPUT
# SemVer
"instance-management-semver=$($appVersion -Replace $prefix)" >> $env:GITHUB_OUTPUT
- name: Setup .NET
uses: actions/setup-dotnet@87b7050bc53ea08284295505d98d2aa94301e852 # v4.2
with:
dotnet-version: 8.0.x
- name: Publish .NET Assemblies
run: |
$appVersion = "${{ steps.versions.outputs.instance-management-semver }}"
./build.ps1 -Command BuildAndPublish `
-Configuration Release `
-Version $appVersion
- name: Setup Nuget.exe
uses: nuget/setup-nuget@323ab0502cd38fdc493335025a96c8fdb0edc71f #v2.0.1
- name: Create NuGet Packages
if: success()
run: |
$appVersion = "${{ steps.versions.outputs.instance-management-semver }}"
"Building ${{ env.PACKAGE_NAME }} NuGet Package" | Write-Output
# installer and Transform load to single package
./build.ps1 -Command Package `
-Version $appVersion `
-Configuration Release
- name: Generate hash for NuGet package
id: hash-code
shell: bash
run: |
echo "hash-code=$(sha256sum *.nupkg | base64 -w0)" >> $GITHUB_OUTPUT
- name: Upload Packages as Artifacts
if: success()
uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6
with:
name: "${{ env.PACKAGE_NAME }}-NuGet"
path: ./*.nupkg
if-no-files-found: error
retention-days: 30
docker-analysis:
runs-on: ubuntu-latest
permissions:
security-events: write
pull-requests: write
strategy:
fail-fast: false
matrix:
dockerfile:
[ { name: "development", path: "docker/Dockerfile", type: "local" } ]
steps:
- name: Checkout code
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Log in to Docker Hub
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.0
with:
username: ${{ env.DOCKER_USERNAME }}
password: ${{ env.DOCKER_HUB_TOKEN }}
- name: Build
run: |
dockerfile=$(echo ${{matrix.dockerfile.path}})
docker build -f $dockerfile -t ${{ matrix.dockerfile.name }} --build-arg="pre" .
- name: Analyze
uses: docker/scout-action@67eb1afe777307506aaecb9acd9a0e0389cb99ae # v1.5.0
with:
command: cves
image: local://${{ matrix.dockerfile.name }}
sarif-file: sarif-${{ matrix.dockerfile.name }}.output.json
summary: true
- name: Upload SARIF result
id: upload-sarif
if: ${{ github.event_name != 'pull_request_target' }}
uses: github/codeql-action/upload-sarif@48ab28a6f5dbc2a99bf1e0131198dd8f1df78169 #codeql-bundle-v3.28.0
with:
sarif_file: sarif-${{ matrix.dockerfile.name }}.output.json
docker-publish:
name: Publish to Docker Hub
permissions:
actions: read
contents: write
runs-on: ubuntu-latest
needs:
- pack
- docker-analysis
steps:
- name: Wait 20s
# Give Azure Artifacts caching a moment to catch up
run: sleep 20
- name: Prepare Tags
id: prepare-tags
run: |
BASE="${{ env.IMAGE_NAME }}"
REF="${{ env.REF }}"
if [[ $REF =~ "pre" ]]
then
# Pre-releases get the version and the tag "pre"
TAGS="${{ env.IMAGE_NAME }}:${REF},${{ env.IMAGE_NAME }}:pre"
else
# Releases get the version, plus shortened form for minor release.
# We are not using shortened form for major or using "latest"
# because they are too imprecise.
MINOR=`echo ${REF} | awk -F"." '{print $1"."$2}'`
TAGS="${{ env.IMAGE_NAME }}:${REF},${{ env.IMAGE_NAME }}:${MINOR}"
fi
echo "TAGS=$TAGS" >> $GITHUB_OUTPUT
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@6524bf65af31da8d45b59e8c27de4bd072b392f5 # v3.8.0
- name: Log in to Docker Hub
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.0
with:
username: ${{ env.DOCKER_USERNAME }}
password: ${{ env.DOCKER_HUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@369eb591f429131d6889c46b94e711f089e6ca96 # v5.6.1
with:
images: ${{ env.IMAGE_NAME }}
- name: Build and push
uses: docker/build-push-action@b32b51a8eda65d6793cd0494a773d4f6bcef32dc # v6.11.0
with:
context: "{{defaultContext}}:/"
cache-from: type=registry,ref=${{ env.IMAGE_NAME }}:pre
cache-to: type=inline
build-args: ML_VERSION=${{ steps.prepare-tags.outputs.NPM_VERSION }} #Ask Jesus which version to use
file: docker/Dockerfile
tags: ${{ steps.prepare-tags.outputs.TAGS }}
labels: ${{ steps.meta.outputs.labels }}
push: true
sbom-create:
name: Create SBOM
runs-on: ubuntu-latest
needs: pack
permissions:
actions: read
contents: write
outputs:
sbom-hash-code: ${{ steps.sbom-hash-code.outputs.sbom-hash-code }}
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Get Artifacts
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 #v4.1.8
with:
name: ${{ env.PACKAGE_NAME }}-NuGet
- name: Generate Software Bill of Materials (SBOM) - API
shell: pwsh
run: |
$packageName = "${{ env.PACKAGE_NAME }}"
$version = "${{ needs.pack.outputs.instance-management-version }}"
Get-ChildItem -Include "$packageName.*.nupkg" -Recurse | ForEach-Object { $_.FullName } > buildfilelist.txt
dotnet tool install --global Microsoft.Sbom.DotNetTool
sbom-tool generate `
-b ./ `
-bl ./buildfilelist.txt `
-bc "./" `
-pn "$packageName" `
-pv $version `
-nsb https://ed-fi.org `
-m ./ `
-ps "Ed-Fi Alliance"
- name: Upload SBOM
if: success()
uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6
with:
name: ${{ env.PACKAGE_NAME }}-SBOM
path: ${{ env.MANIFEST_FILE }}
if-no-files-found: error
retention-days: 30
- name: Generate hash code for SBOM
id: sbom-hash-code
shell: bash
run: |
# sha256sum returns "<hashcode> <name of file". Split that and return only the <hashcode>.
sbom_hash=$(sha256sum ./${{ env.MANIFEST_FILE }} | awk '{split($0,a); print a[1]}')
echo "sbom-hash-code=$sbom_hash" >> $GITHUB_OUTPUT
sbom-attach:
name: Attach SBOM file
runs-on: ubuntu-latest
needs:
- sbom-create
- pack
permissions:
actions: read
contents: write
steps:
- name: Download the SBOM
uses: Ed-Fi-Alliance-OSS/slsa-github-generator/.github/actions/secure-download-artifact@main
with:
name: "${{ env.PACKAGE_NAME }}-SBOM"
path: ${{ env.MANIFEST_FILE }}
sha256: "${{ needs.sbom-create.outputs.sbom-hash-code }}"
- name: Attach to release
shell: pwsh
run: |
$release = "${{ github.ref_name }}"
$repo = "${{ github.repository }}"
$token = "${{ secrets.GITHUB_TOKEN }}"
$file = "${{ env.MANIFEST_FILE }}"
$uploadName = "${{ env.PACKAGE_NAME }}-SBOM.zip"
$url = "https://api.github.com/repos/$repo/releases/tags/$release"
$gh_headers = @{
"Accept" = "application/vnd.github+json"
"Authorization" = "Bearer $token"
}
$response = Invoke-RestMethod -Uri $url -Headers $gh_headers
$releaseId = $response.id
$url = "https://uploads.github.com/repos/$repo/releases/$releaseId/assets"
Compress-Archive $file -DestinationPath $uploadName
$gh_headers["Content-Type"] = "application/octet"
Invoke-RestMethod -Method POST `
-Uri "$($url)?name=$($uploadName)" `
-Headers $gh_headers `
-InFile $uploadName
provenance-create:
name: Create Provenance
needs: pack
permissions:
actions: read
id-token: write
contents: write
uses: Ed-Fi-Alliance-OSS/slsa-github-generator/.github/workflows/generator_generic_slsa3.yml@v2.0.0
with:
base64-subjects: ${{ needs.pack.outputs.hash-code }}
provenance-name: InstanceManagement.intoto.jsonl
upload-assets: true
# TODO: remove this after this issue is resolved: https://github.com/slsa-framework/slsa-github-generator/issues/876
compile-generator: true
publish-package:
name: Publish NuGet Package
needs: pack
runs-on: ubuntu-latest
defaults:
run:
shell: pwsh
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Get Artifact
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 #v4.1.8
with:
name: ${{ env.PACKAGE_NAME }}-NuGet
- name: Install-credential-handler
run: iex "& { $(irm https://aka.ms/install-artifacts-credprovider.ps1) } -AddNetfx"
- name: Push Package to Azure Artifacts
run: |
$artifact = (Get-ChildItem -Path $_ -Name -Include *.nupkg)
$arguments = @{
EdFiNuGetFeed = "${{ env.ARTIFACTS_FEED_URL }}"
NuGetApiKey = "${{ env.ARTIFACTS_API_KEY }}"
}
$artifact | ForEach-Object {
$arguments.PackageFile = $_
./build.ps1 Push @arguments
}