Skip to content

On Pre-Release

On Pre-Release #106

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
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 }}"}]}'
MANIFEST_FILE: "_manifest/spdx_2.2/manifest.spdx.json"
PACKAGE_NAME: "AdminApp.Web"
IMAGE_NAME: ${{ vars.IMAGE_NAME }}
ADMINAPP_SQL_IMAGE_NAME: ${{ vars.ADMINAPP_SQL_IMAGE_NAME}}
DOCKER_USERNAME: ${{ vars.DOCKER_USERNAME }}
DOCKER_HUB_TOKEN: ${{ secrets.DOCKER_HUB_TOKEN }}
REF: ${{ github.ref_name }}
jobs:
pack:
name: Build and Pack
runs-on: ubuntu-latest
defaults:
run:
shell: pwsh
outputs:
hash-code: ${{ steps.hash-code.outputs.hash-code }}
admin-app-version: ${{ steps.versions.outputs.admin-app }}
steps:
- uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0
with:
fetch-depth: 0
- name: Set Version Numbers
id: versions
run: |
$webPrefix = "v"
# Install the MinVer CLI tool
&dotnet tool install --global minver-cli
$appVersion = $(minver -t $webPrefix)
# Full release name
"admin-app=$appVersion" >> $env:GITHUB_OUTPUT
# SemVer
"admin-app-semver=$($appVersion -Replace $webPrefix)" >> $env:GITHUB_OUTPUT
- name: Setup .NET
uses: actions/setup-dotnet@607fce577a46308457984d59e4954e075820f10a # v3.0.3
with:
dotnet-version: 8.0.x
- name: Publish .NET Assemblies
run: |
$appVersion = "${{ steps.versions.outputs.admin-app-semver }}"
./build.ps1 -Command BuildAndPublish `
-Configuration Release `
-Version $appVersion
- name: Setup Nuget.exe
uses: nuget/setup-nuget@fd9fffd6ca4541cf4152a9565835ca1a88a6eb37 #v1.1.1
- name: Create NuGet Packages
if: success()
run: |
$appVersion = "${{ steps.versions.outputs.admin-app-semver }}"
"Building ${{ env.PACKAGE_NAME }} NuGet Package" | Write-Output
# Web, and DB
./build.ps1 -Command Package `
-Version $appVersion `
-Configuration Release
./build.ps1 -Command PackageDatabase `
-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@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2
with:
name: "${{ env.PACKAGE_NAME }}-NuGet"
path: ./*.nupkg
if-no-files-found: error
retention-days: 30
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@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0
- name: Get Artifacts
uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a #v3.0.2
with:
name: ${{ env.PACKAGE_NAME }}-NuGet
- name: Generate Software Bill of Materials (SBOM) - API
shell: pwsh
run: |
$packageName = "${{ env.PACKAGE_NAME }}"
$url = "https://github.com/microsoft/sbom-tool/releases/latest/download/sbom-tool-linux-x64"
$out = "$($env:RUNNER_TEMP)/sbom-tool"
Invoke-RestMethod -Uri $url -OutFile $out
chmod +x $out
Get-ChildItem -Include "EdFi.Suite3.ODS.$packageName.*.nupkg" -Recurse | ForEach-Object { $_.FullName } > buildfilelist.txt
New-Item -Path manifest -Type Directory
$version = "${{ needs.pack.outputs.admin-app-version }}"
&$out generate `
-b ./ `
-bl ./buildfilelist.txt `
-bc "./Application/EdFi.Ods.$packageName" `
-pn "EdFi.Suite3.ODS.$packageName" `
-pv $version `
-nsb https://ed-fi.org `
-m manifest `
-ps "Ed-Fi Alliance"
- name: Upload SBOM
if: success()
uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2
with:
name: ${{ env.PACKAGE_NAME }}-SBOM
path: ./manifest
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 ./manifest/${{ 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: slsa-framework/slsa-github-generator/.github/actions/secure-download-artifact@7f4fdb871876c23e455853d694197440c5a91506 #v1.5.0
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@main
with:
base64-subjects: ${{ needs.pack.outputs.hash-code }}
provenance-name: AdminApp.Web.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@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0
- name: Get Artifact
uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a #v3.0.2
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
}
docker-publish:
name: Publish to Docker Hub
runs-on: ubuntu-latest
needs:
- publish-package
steps:
- name: Wait 20s
# Give Azure Artifacts caching a moment to catch up
run: sleep 20
- name: Prepare Tags
id: prepare-tags
run: |
REF="${{ env.REF }}"
if [[ $REF =~ "Pre-Release" ]]
then
# Remove Pre-Release prefix
PREFIX="Pre-Release-"
PACKAGEVERSION=${REF#"$PREFIX"}
else
PACKAGEVERSION=${REF}
fi
if [[ $PACKAGEVERSION =~ "alpha" ]]
then
# Pre-releases get the tag "pre"
AATAGS="${{ env.IMAGE_NAME }}:pre"
AASQLTAGS="${{ env.ADMINAPP_SQL_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 ${PACKAGEVERSION} | awk -F"." '{print $1"."$2}'`
AATAGS="${{ env.IMAGE_NAME }}:${PACKAGEVERSION},${{ env.IMAGE_NAME }}:${MINOR}"
AASQLTAGS="${{ env.ADMINAPP_SQL_IMAGE_NAME }}:${PACKAGEVERSION},${{ env.ADMINAPP_SQL_IMAGE_NAME }}:${MINOR}"
fi
SEMVERSION=${PACKAGEVERSION:1} # strip off the leading 'v'
echo "AATAGS=$AATAGS" >> $GITHUB_OUTPUT
echo "AASQLTAGS=$AASQLTAGS" >> $GITHUB_OUTPUT
echo "VERSION=$SEMVERSION" >> $GITHUB_OUTPUT
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@4b4e9c3e2d4531116a6f8ba8e71fc6e2cb6e6c8c # v2.5.0
- name: Log in to Docker Hub
uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a # v2.1.0
with:
username: ${{ env.DOCKER_USERNAME }}
password: ${{ env.DOCKER_HUB_TOKEN }}
- name: Extract metadata (tags, labels) for admin app image
id: metaapi
uses: docker/metadata-action@507c2f2dc502c992ad446e3d7a5dfbe311567a96 # v4.3.0
with:
images: ${{ env.IMAGE_NAME }}
- name: Build and push admin app image
uses: docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09 # v5.0.0
with:
context: "{{defaultContext}}:Docker"
cache-from: type=registry,ref=${{ env.IMAGE_NAME }}:pre
cache-to: type=inline
build-args: VERSION=${{ steps.prepare-tags.outputs.VERSION }}
file: pgsql.Dockerfile
tags: ${{ steps.prepare-tags.outputs.AATAGS }}
labels: ${{ steps.metaapi.outputs.labels }}
push: true
- name: Extract metadata (tags, labels) for admin app sql image
id: metadatabase
uses: docker/metadata-action@507c2f2dc502c992ad446e3d7a5dfbe311567a96 # v4.3.0
with:
images: ${{ env.ADMINAPP_SQL_IMAGE_NAME }}
- name: Build and push admin app sql image
uses: docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09 # v5.0.0
with:
context: "{{defaultContext}}:Docker"
cache-from: type=registry,ref=${{ env.ADMINAPP_SQL_IMAGE_NAME }}:pre
cache-to: type=inline
build-args: VERSION=${{ steps.prepare-tags.outputs.VERSION }}
file: mssql.Dockerfile
tags: ${{ steps.prepare-tags.outputs.AASQLTAGS }}
labels: ${{ steps.metadatabase.outputs.labels }}
push: true