Skip to content

feat: initial commit action-generic-build-package #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
15 changes: 15 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
root = true

[*]
charset = utf-8
end_of_line = lf
indent_size = 4
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true

[*.md]
trim_trailing_whitespace = false

[*.{yml,yaml}]
indent_size = 2
62 changes: 62 additions & 0 deletions .github/actions/build-package/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: "Creates a source package for an application"
description: "Creates a tarball of source files and upload it as an artifact."

inputs:
package_file_name:
description: "Name of the package (without extension) for example: nl-example-package."
required: true
include_paths:
description: "A space-separated list of paths to include in the package relative to the working_directory."
required: false
default: "."
working_directory:
description: "The base directory containing the source code, only required if it does not need to be the root folder."
required: false
default: "."
version_json_path:
description: "The location where version.json needs to be stored. For example `public/version.json`."
required: false
default: "version.json"
checkout_repository:
description: "Whether to checkout the repository (true or false)."
required: false
default: 'true'

runs:
using: "composite"
steps:
- name: Checkout code
if: inputs.checkout_repository == 'true'
uses: actions/checkout@v4

- name: Extract version from tag
shell: bash
run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV

- name: Set package file name
shell: bash
run: echo "PACKAGE_FILE_NAME=${{ inputs.package_file_name }}_${{ env.RELEASE_VERSION }}" >> $GITHUB_ENV

- name: Set GitHub Path
run: echo "$GITHUB_ACTION_PATH" >> $GITHUB_PATH
shell: bash
env:
GITHUB_ACTION_PATH: ${{ github.action_path }}

- name: Create package archive
shell: bash
run: |
build-src-package.sh \
--base-dir "${{ inputs.working_directory }}" \
--includes "${{ inputs.include_paths }}" \
--version ${{ env.RELEASE_VERSION }} \
--version-json-path "${{ inputs.version_json_path }}" \
--git-ref ${{ github.sha }} \
--output "${{ env.PACKAGE_FILE_NAME }}.tar.gz"

- name: Upload package artifact
uses: actions/upload-artifact@v4
with:
name: ${{ env.PACKAGE_FILE_NAME }}
path: ${{ env.PACKAGE_FILE_NAME }}.tar.gz
if-no-files-found: error
112 changes: 112 additions & 0 deletions .github/actions/build-package/build-src-package.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
#!/bin/bash
set -euo pipefail

# Default values
GIT_REF=$(git rev-parse HEAD 2>/dev/null || echo "local")
INCLUDES=()
RELEASE_VERSION=""
ORIGINAL_DIR=$(pwd)
OUTPUT_FILE=""
BASE_DIR=""
VERSION_JSON_PATH="version.json"

function show_help {
echo "Usage: $0 [options]"
echo ""
echo "Build a release package with source files for an application"
echo ""
echo "Options:"
echo " --base-dir The base source directory (REQUIRED)"
echo " --includes A space-separated list of paths to include in the package relative to the --base-dir (REQUIRED)"
echo " --version Release version (REQUIRED)"
echo " --output Output file name (REQUIRED)"
echo " --git-ref Git reference (default: current HEAD)"
echo " --version-json-path The location where version.json needs to be stored (default: version.json)"
echo " --help Display this help message"
echo ""
echo "Example:"
echo " $0 --base-dir \".\" --includes \"app\" --version v1.0.0 --output mypackage.tar.gz"
}

# Parse command-line arguments
while [[ $# -gt 0 ]]; do
case $1 in
--base-dir)
BASE_DIR="$2"
shift 2
;;
--includes)
INCLUDES="$2"
shift 2
;;
--version)
RELEASE_VERSION="$2"
shift 2
;;
--output)
OUTPUT_FILE="$2"
shift 2
;;
--git-ref)
GIT_REF="$2"
shift 2
;;
--version-json-path)
VERSION_JSON_PATH="$2"
shift 2
;;
--help)
show_help
exit 0
;;
*)
echo "Unknown option: $1"
show_help
exit 1
;;
esac
done

# Required argument checks
[ -z "$BASE_DIR" ] && { echo "ERROR: Source dir is required. Use --base-dir to set it."; show_help; exit 1; }
[ -z "$INCLUDES" ] && { echo "ERROR: Include paths are required. Use --includes to set it."; show_help; exit 1; }
[ -z "$RELEASE_VERSION" ] && { echo "ERROR: Release version is required. Use --version to set it."; show_help; exit 1; }
[ -z "$OUTPUT_FILE" ] && { echo "ERROR: Output file name is required. Use --output to set it."; show_help; exit 1; }

WORK_DIR="/tmp/package-${OUTPUT_FILE}"

echo "Creating release package with the following settings:"
echo " Version: ${RELEASE_VERSION}"
echo " Git ref: ${GIT_REF}"
echo " Output: ${OUTPUT_FILE}"
echo " Included paths: ${INCLUDES}"
echo " version.json path: ${VERSION_JSON_PATH}"

# Create a clean working directory
rm -rf "${WORK_DIR}"
mkdir -p "${WORK_DIR}"

# Copy source files from the specified source directory
cp -r "${BASE_DIR}"/* "${WORK_DIR}/"

# Ensure the directory for version.json exists
VERSION_JSON_DIR=$(dirname "${WORK_DIR}/${VERSION_JSON_PATH}")
mkdir -p "${VERSION_JSON_DIR}"

# Create or update the version.json with version and git_ref
VERSION_JSON_FULL_PATH="${WORK_DIR}/${VERSION_JSON_PATH}"
echo '{
"version": "'${RELEASE_VERSION}'",
"git_ref": "'${GIT_REF}'"
}' > "${VERSION_JSON_FULL_PATH}"

echo "Creating archive ${OUTPUT_FILE}..."

# Create an empty file to avoid tar errors
touch "${ORIGINAL_DIR}/${OUTPUT_FILE}"

# Always include version.json in the tar
EXTRA_INCLUDES="${VERSION_JSON_PATH}"
tar -zcvf "${ORIGINAL_DIR}/${OUTPUT_FILE}" -C "${WORK_DIR}" ${INCLUDES} ${EXTRA_INCLUDES}

echo "You can inspect the contents with: tar -tvf ${ORIGINAL_DIR}/${OUTPUT_FILE}"
15 changes: 15 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"

- package-ecosystem: github-actions
directory: /.github/actions/build-package
schedule:
interval: 'weekly'
groups:
actions:
patterns:
- "actions/*"
15 changes: 15 additions & 0 deletions .github/workflows/documentation-linter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: lint documentation
on:
pull_request:
paths:
- '**.md'
jobs:
mdlint:
name: lint markDown file
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: DavidAnson/markdownlint-cli2-action@v20
with:
globs: '**/*.md'
config: .markdownlint.json
12 changes: 12 additions & 0 deletions .markdownlint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"MD013": {
"line_length": 256,
"ignore_code_blocks": true
},
"MD033": {
"allowed_elements": ["details", "summary"]
},
"MD024": {
"siblings_only": true
}
}
Loading