Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,10 @@ jobs:
GITHUB_REPOSITORY: ${{ github.repository }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: ./build.bash -p

- uses: actions/upload-artifact@v4
with:
name: Buildscript
path: package/buildscript-*.zip
if-no-files-found: ignore

12 changes: 10 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
## [1.3.3] - 2025-10-09

- Revert broken build changes
- Improve release-prep.bash and release-publish.bash scripts
- Change to manual deployment method
- Revise and streamline Dockerfile
- Add copy of release-publish script to Dockerfile

## [1.3.2] - 2025-09-17

Expand Down Expand Up @@ -49,7 +55,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- GitHub workflow `build.yml` to show how to call the script as a GitHub Action

[unreleased]: https://github.com/mcld/buildscript/compare/v1.3.0...HEAD
[1.2.0]: https://github.com/mcld/buildscript/compare/v1.2.0...v1.3.0
[1.3.3]: https://github.com/mcld/buildscript/compare/v1.3.2...v1.3.3
[1.3.2]: https://github.com/mcld/buildscript/compare/v1.3.0...v1.3.2
[1.3.0]: https://github.com/mcld/buildscript/compare/v1.2.0...v1.3.0
[1.2.0]: https://github.com/mcld/buildscript/compare/v1.1.0...v1.2.0
[1.1.0]: https://github.com/mcld/buildscript/compare/v1.0.1...v1.1.0
[1.0.1]: https://github.com/mcld/buildscript/compare/v1.0.0...v1.0.1
Expand Down
73 changes: 41 additions & 32 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,51 +1,60 @@
# prepare base image
FROM mcr.microsoft.com/dotnet/runtime:8.0 AS base
# Get build image
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build

WORKDIR /app

# get build image
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
WORKDIR /src
# Copy source
COPY . ./

# Bring in metadata via --build-arg for build
ARG IMAGE_VERSION=unknown

# run dotnet restore
COPY ["buildscript/buildscript.csproj", "buildscript/"]
RUN dotnet restore "buildscript/buildscript.csproj"
# Restore packages
RUN dotnet restore

# copy source and build
COPY . .
WORKDIR "/src/buildscript"
RUN dotnet build "buildscript.csproj" -c Release -o /app/build
# Build project and run tests
RUN dotnet test -v m /property:WarningLevel=0

# create publish image
FROM build AS publish
RUN dotnet publish "buildscript.csproj" -c Release -o /app/publish
# Publish release project
RUN dotnet publish -v m /property:WarningLevel=0 -c Release --property:PublishDir=/app/publish/

# Copy release-publish.bash script
RUN cp /app/release-publish.bash "/app/publish/"

# Copy actual build script
RUN cp /app/build.bash "/app/publish/"

# Get runtime image
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS publish

# copy published app to final
FROM base AS final
WORKDIR /app

# Bring in metadata via --build-arg
# Bring in metadata via --build-arg to publish
ARG BRANCH=unknown
ARG IMAGE_CREATED=unknown
ARG IMAGE_REVISION=unknown
ARG IMAGE_VERSION=unknown

# Configure image labels
LABEL branch=$branch \
maintainer="Maricopa County Library District developers <development@mcldaz.org>" \
org.opencontainers.image.authors="Maricopa County Library District developers <development@mcldaz.org>" \
org.opencontainers.image.created=$IMAGE_CREATED \
org.opencontainers.image.description="Build script test project" \
org.opencontainers.image.licenses="MIT" \
org.opencontainers.image.revision=$IMAGE_REVISION \
org.opencontainers.image.source="https://github.com/MCLD/buildscript" \
org.opencontainers.image.title="Build script test project" \
org.opencontainers.image.vendor="Maricopa County Library District" \
org.opencontainers.image.version=$IMAGE_VERSION
LABEL branch=$BRANCH \
maintainer="Maricopa County Library District developers <development@mcldaz.org>" \
org.opencontainers.image.authors="Maricopa County Library District developers <development@mcldaz.org>" \
org.opencontainers.image.created=$IMAGE_CREATED \
org.opencontainers.image.description="Build script test project" \
org.opencontainers.image.licenses="MIT" \
org.opencontainers.image.revision=$IMAGE_REVISION \
org.opencontainers.image.source="https://github.com/MCLD/buildscript" \
org.opencontainers.image.title="Build scrip test project" \
org.opencontainers.image.vendor="Maricopa County Library District" \
org.opencontainers.image.version=$IMAGE_VERSION

# Default image environment variable settings
ENV org.opencontainers.image.created=$IMAGE_CREATED \
org.opencontainers.image.revision=$IMAGE_REVISION \
org.opencontainers.image.version=$IMAGE_VERSION
org.opencontainers.image.revision=$IMAGE_REVISION \
org.opencontainers.image.version=$IMAGE_VERSION

# Copy source
COPY --from=build "/app/publish/" .

COPY --from=publish /app/publish .
# Set entrypoint
ENTRYPOINT ["dotnet", "buildscript.dll"]
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Options (all are optional):
- `-h, --help` - Print this help and exit
- `-v, --verbose` - Print script debug info
- `-df, --dockerfile` - Use the specified Dockerfile
- `-p, --publish` - Run the release-publish.bash script in the container (if it's present)
- `-p, --publish` - Run the release-prep and (in container) release-publish scripts (if present)
- `Docker tag` - Override the guessed Docker tag (the current directory) with this value if present

Environment variables (all are optional):
Expand Down
15 changes: 7 additions & 8 deletions build.bash
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ Available options:
-h, --help Print this help and exit
-v, --verbose Print script debug info
-df, --dockerfile Use the specified Dockerfile
-p, --publish Run the release-publish.bash script in the container (if it's present)
--no-color Do not use color codes in script output
-p, --publish Run release-prep.bash and (in container) release-publish.bash (if present)

Environment variables:

Expand All @@ -38,7 +39,7 @@ Environment variables:
- GHCR_PAT - optional - GitHub Container Registry Personal Access Token
- GHCR_USER - optional - username to log in to the GitHub Container Registry

Version 1.3.2 released 2025-09-17
Version 1.3.3 released 2025-10-09
EOF
exit
}
Expand Down Expand Up @@ -116,7 +117,7 @@ readonly SYSARCH

if [[ ${SYSARCH} = "i386" ]]; then
readonly ARCH="x86_32"
elif [[ ${SYSARCH} = "aarch64" ]]; then
elif [[ ${SYSARCH} = "aarch64" ]]; then
readonly ARCH="armv7"
else
readonly ARCH=${SYSARCH}
Expand Down Expand Up @@ -162,11 +163,11 @@ fi
if [[ $BLD_BRANCH = "develop"
|| $BLD_BRANCH = "main"
|| $BLD_BRANCH = "master"
|| $BLD_BRANCH = "test" ]]; then
|| $BLD_BRANCH = "test" ]]; then
BLD_DOCKER_TAG=$BLD_BRANCH
BLD_VERSION=${BLD_BRANCH}-${BLD_VERSION_DATE}
BLD_PUSH=true
elif [[ "$BLD_BRANCH" =~ release/([0-9]+\.[0-9]+\.[0-9]+.*) ]]; then
elif [[ "$BLD_BRANCH" =~ release/([0-9]+\.[0-9]+\.[0-9]+.*) ]]; then
BLD_RELEASE_VERSION=${BASH_REMATCH[1]}
BLD_DOCKER_TAG=v${BLD_RELEASE_VERSION}
BLD_VERSION=v${BLD_RELEASE_VERSION}
Expand Down Expand Up @@ -202,7 +203,7 @@ fi
if [[ $BLD_RELEASE = "true" && -x "release-prep.bash" ]]; then
msg "${BLUE}===${NOFORMAT} Running release preparation for version $BLD_RELEASE_VERSION"
#shellcheck disable=SC1091
./release-prep.bash
source release-prep.bash
msg "${GREEN}===${NOFORMAT} Release preparation script complete"
fi

Expand Down Expand Up @@ -311,15 +312,13 @@ if [[ $BLD_PUSH = true ]]; then
--entrypoint "/app/release-publish.bash" \
--env-file release.env \
-e BLD_RELEASE_VERSION="$BLD_RELEASE_VERSION" \
-v "${PWD}/:/app" \
-v "${PWD}/package:/package" \
"$BLD_FULL_DOCKER_IMAGE"
else
docker run -i \
--rm \
--entrypoint "/app/release-publish.bash" \
-e BLD_RELEASE_VERSION="$BLD_RELEASE_VERSION" \
-v "${PWD}/:/app" \
-v "${PWD}/package:/package" \
"$BLD_FULL_DOCKER_IMAGE"
fi
Expand Down
2 changes: 2 additions & 0 deletions buildscript.sln
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
.gitignore = .gitignore
azure-pipelines.yml = azure-pipelines.yml
build.bash = build.bash
CHANGELOG.md = CHANGELOG.md
.github\workflows\ci.yml = .github\workflows\ci.yml
Dockerfile = Dockerfile
LICENSE.md = LICENSE.md
README.md = README.md
release-prep.bash = release-prep.bash
release-publish.bash = release-publish.bash
Expand Down
79 changes: 43 additions & 36 deletions release-prep.bash
Original file line number Diff line number Diff line change
Expand Up @@ -7,68 +7,75 @@ script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd -P)

usage() {
cat <<EOF
Usage: $(basename "${BASH_SOURCE[0]}") [-h] [-v] [-f] -p param_value arg1 [arg2...]
Usage: $(basename "${BASH_SOURCE[0]}") [-h] [-v]

Fake release prep script.
Pre-build release preparation script

Available options:

-h, --help Print this help and exit
--no-color Do not use color codes in script output
-p Perform publish steps
-v, --verbose Print script debug info
EOF
exit
exit
}

cleanup() {
trap - SIGINT SIGTERM ERR EXIT
# script cleanup here
trap - SIGINT SIGTERM ERR EXIT
# script cleanup here
}

setup_colors() {
if [[ -t 2 ]] && [[ -z "${NO_COLOR-}" ]] && [[ "${TERM-}" != "dumb" ]]; then
NOFORMAT='\033[0m' RED='\033[0;31m' GREEN='\033[0;32m' ORANGE='\033[0;33m' BLUE='\033[0;34m' PURPLE='\033[0;35m' CYAN='\033[0;36m' YELLOW='\033[1;33m'
else
NOFORMAT='' RED='' GREEN='' ORANGE='' BLUE='' PURPLE='' CYAN='' YELLOW=''
fi
if [[ -t 2 ]] && [[ -z "${NO_COLOR-}" ]] && [[ "${TERM-}" != "dumb" ]]; then
NOFORMAT='\033[0m' RED='\033[0;31m' GREEN='\033[0;32m' ORANGE='\033[0;33m' BLUE='\033[0;34m' PURPLE='\033[0;35m' CYAN='\033[0;36m' YELLOW='\033[1;33m'
else
NOFORMAT='' RED='' GREEN='' ORANGE='' BLUE='' PURPLE='' CYAN='' YELLOW=''
fi
}

msg() {
echo >&2 -e "${1-}"
echo >&2 -e "${1-}"
}

die() {
local msg=$1
local code=${2-1} # default exit status 1
msg "$msg"
exit "$code"
local msg=$1
local code=${2-1} # default exit status 1
msg "$msg"
exit "$code"
}

parse_params() {
# default values of variables set from params
flag=0
param=''

while :; do
case "${1-}" in
-h | --help) usage ;;
-v | --verbose) set -x ;;
--no-color) NO_COLOR=1 ;;
-?*) die "Unknown option: $1" ;;
*) break ;;
esac
shift
done

args=("$@")

return 0
# default values of variables set from params
publish=0

while :; do
case "${1-}" in
-h | --help) usage ;;
-v | --verbose) set -x ;;
--no-color) NO_COLOR=1 ;;
-p | --publish) publish=1 ;;
-?*) die "Unknown option: $1" ;;
*) break ;;
esac
shift
done

return 0
}

parse_params "$@"
setup_colors

# script logic here

msg "... release-prep.bash is preparing for release"
sleep 2
msg "... release-prep.bash has prepared for release."
readonly PUB_STARTAT=$SECONDS

if [[ publish -eq 1 ]]; then
msg "${BLUE}===${NOFORMAT} Performing publish release prep"
sleep 2
msg "${PURPLE}===${NOFORMAT} Release prep successful in $((SECONDS - PUB_STARTAT)) seconds."
else
msg "${RED}===${NOFORMAT} Missing -p flag, not running release prep"
fi

37 changes: 12 additions & 25 deletions release-publish.bash
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ usage() {
cat <<EOF
Usage: $(basename "${BASH_SOURCE[0]}") [-h] [-v] [-f] -p param_value arg1 [arg2...]

Script description here.
Post-build release processing script

Available options:

-h, --help Print this help and exit
--no-color Do not use color codes in script output
-v, --verbose Print script debug info
EOF
exit
Expand Down Expand Up @@ -63,34 +64,20 @@ parse_params() {
parse_params "$@"
setup_colors

readonly BLD_PUBLISH_DIRECTORY=buildscript-${BLD_RELEASE_VERSION-}
#script logic here

msg "=== Installing necessary packages"
apt update && apt install build-essential zip -y
readonly PUB_STARTAT=$SECONDS

cd /
msg "${BLUE}===${NOFORMAT} Installing zip package"

msg "=== Making directory ${BLD_PUBLISH_DIRECTORY-}"
mkdir -p "${BLD_PUBLISH_DIRECTORY-}"
apt-get update && apt-get install zip -y

msg "=== Copying files into ${BLD_PUBLISH_DIRECTORY-}"
cp -a app/* "${BLD_PUBLISH_DIRECTORY-}"
msg "${BLUE}===${NOFORMAT} Publishing to buildscript-${BLD_RELEASE_VERSION}.zip"

msg "=== Compressing files"
zip -q -r9 "buildscript-${BLD_RELEASE_VERSION-}.zip" "${BLD_PUBLISH_DIRECTORY-}"/
mkdir -p "/package" && \
cd /app && \
zip -q -r9 "/package/buildscript-${BLD_RELEASE_VERSION}.zip" "build.bash" && \
du -sh "/package/buildscript-${BLD_RELEASE_VERSION}.zip"

du -sch "${BLD_PUBLISH_DIRECTORY-}"/ "buildscript-${BLD_RELEASE_VERSION-}.zip"
msg "${PURPLE}===${NOFORMAT} Publish script complete in $((SECONDS - PUB_STARTAT)) seconds."

if [[ -n "${BLD_RELEASE_TOKEN-}" ]]; then
curl -L -O https://github.com/tfausak/github-release/releases/latest/download/github-release-linux.gz
gunzip github-release-linux.gz && chmod 700 github-release-linux && \
./github-release-linux upload \
--token "${BLD_RELEASE_TOKEN-}" \
--owner "${BLD_RELEASE_OWNER-}" \
--repo "${BLD_RELEASE_REPO-}" \
--tag "v${BLD_RELEASE_VERSION-}" \
--file "buildscript-${BLD_RELEASE_VERSION-}.zip" \
--name "buildscript-${BLD_RELEASE_VERSION-}.zip"
else
echo "=== No BLD_RELEASE_TOKEN configured, not pushing release artifacts to GitHub Releases"
fi