Skip to content

Commit

Permalink
package: fix relative paths and embedded composite actions
Browse files Browse the repository at this point in the history
Fix several small issues that make it possible to migrate from the prior
Docker based version to the composite action version

* Check out the action repo into a different directory when building nfpm
* Execute nfpm from the root workspace directory to support relative
  paths in configs
* Work around runners bugs when executing composite actions inside the
  scope of other composite actions.

Signed-off-by: Ryan Cragun <[email protected]>
  • Loading branch information
ryancragun committed May 9, 2024
1 parent 90478df commit f8956bc
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
working-directory: build
run: |
go build -o template .
echo "binary-path=$(readlink -f template)" | tee -a "$GITHUB_OUTPUT"
echo "binary-path=build/template" | tee -a "$GITHUB_OUTPUT"
ls -la
- uses: actions/checkout@v4
with:
Expand Down
50 changes: 40 additions & 10 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,28 @@ inputs:
description: "Where to install the nFPM binary (default: $HOME/bin/nfpm)"
type: string
default: "$HOME/bin/nfpm"
nfpm_template_destination:
description: "Where to install the nfpm_template binary (default: $HOME/bin/nfpm_template)"
type: string
default: "$HOME/bin/nfpm_template"
nfpm_version:
description: "The version of nFPM to install (default: latest)"
type: string
default: Latest
do_not_override_action_ref:
description: |
Don't ever override this. It's a workaround for a runner bug with composite nested actions.
See: https://github.com/actions/runner/issues/2473#issuecomment-1776051383
default: ${{ github.action_ref }}

runs:
using: composite
steps:
- uses: actions/checkout@v4
with:
path: nfpm_packaging
repository: hashicorp/actions-packaging-linux
ref: ${{ inputs.do_not_override_action_ref }}
- name: Install nFPM
working-directory: nfpm_packaging
shell: bash
Expand Down Expand Up @@ -161,9 +172,18 @@ runs:
with:
cache: false
go-version-file: go.mod
- name: Package binary
- name: Build nfpm_template binary
shell: bash
working-directory: nfpm_packaging
run: |
mkdir -p "$(dirname "${{ inputs.nfpm_template_destination }}")"
DESTINATION="$(readlink -f ${{ inputs.nfpm_template_destination }})"
DESTINATION_DIR="$(dirname "$DESTINATION")"
echo "$DESTINATION_DIR" >> "$GITHUB_PATH"
go build -o nfpm_template .
mv nfpm_template "$DESTINATION"
- name: Package binary
shell: bash
env:
# These environment variables are used by the template program that generates the nfpm config
INPUT_NAME: ${{ inputs.name }}
Expand All @@ -184,16 +204,26 @@ runs:
INPUT_POSTREMOVE: ${{ inputs.postremove }}
run: |
if ! fileo=$(file "${{ inputs.binary }}"); then
printf "could not find a binary to package"
printf "could not find binary: $(pwd)\n$(ls)"
exit 1
else
printf "packaging binary %s" "$fileo"
fi
go build -o nfpm_template .
INPUT_DEPENDS="${{ inputs.rpm_depends }}" ./nfpm_template > ./nfpm_rpm_config.yml
INPUT_DEPENDS="${{ inputs.deb_depends }}" ./nfpm_template > ./nfpm_deb_config.yml
cat ./nfpm_*_config.yml
mkdir -p ./out
nfpm package -f ./nfpm_rpm_config.yml -p rpm -t ./out/
nfpm package -f ./nfpm_deb_config.yml -p deb -t ./out/
ls -la ./out
package() {
local config_file
config_file="nfpm_"$1"_config.yml"
if ! INPUT_DEPENDS="$2" nfpm_template > "$config_file"; then
printf "failed to executing nfpm_template for $1"
exit 1
fi
cat "$config_file"
mkdir -p ./out
if ! nfpm package -f "$config_file" -p ${1} -t ./out/; then
printf "failed to create package with nfpm for $1 using config $(cat $config_file)\n"
exit 1
fi
}
package rpm "${{ inputs.rpm_depends }}"
package deb "${{ inputs.deb_depends }}"

0 comments on commit f8956bc

Please sign in to comment.