Skip to content
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

package: fix relative paths and embedded composite actions #22

Merged
merged 2 commits into from
May 9, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I don't think it's helpful to dump the config file a second time, but I do think it's helpful to always dump it. Maybe remove the conditional and let nfpm's non-zero exit directly halt the script and job?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that was an artifact of me debugging and I missed taking it out!

}

package rpm "${{ inputs.rpm_depends }}"
package deb "${{ inputs.deb_depends }}"