Skip to content

Commit

Permalink
Merge pull request #22 from hashicorp/ryan/dont-clobber-caller-checko…
Browse files Browse the repository at this point in the history
…ut-dir

package: fix relative paths and embedded composite actions
  • Loading branch information
ryancragun authored May 9, 2024
2 parents 10b300d + b6416a8 commit 33f7d23
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 10 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
46 changes: 37 additions & 9 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,24 @@ 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"
nfpm package -f "$config_file" -p ${1} -t ./out/
}
package rpm "${{ inputs.rpm_depends }}"
package deb "${{ inputs.deb_depends }}"

0 comments on commit 33f7d23

Please sign in to comment.