Skip to content

Commit

Permalink
Test gh_release
Browse files Browse the repository at this point in the history
  • Loading branch information
nanory committed Nov 24, 2023
1 parent 49de49b commit 8530b1e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
11 changes: 7 additions & 4 deletions .github/workflows/build_pkg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ jobs:
- uses: actions/checkout@v4
with:
repository: gardenlinux/package-build
ref: feature/5-remove-pkg-yml
- run: mkdir input output
- uses: actions/checkout@v4
with:
Expand Down Expand Up @@ -76,6 +77,7 @@ jobs:
)"
echo "pkg=$pkg" | tee -a "$GITHUB_OUTPUT"
echo "build_options=$(cat output/.build_options)" | tee -a "$GITHUB_OUTPUT"
echo "source_name=$(cat output/.source_name)" | tee -a "$GITHUB_OUTPUT"
- name: check if ${{ env.pkg }} already released
id: check
run: |
Expand All @@ -88,11 +90,10 @@ jobs:
id: release
if: ${{ steps.check.outputs.skip_release != 'true' }}
env:
ARTIFACT_NAME: ${{ steps.build.outputs.pkg }}
ARTIFACT_COMMIT: ${{ github.sha }}
PKG_NAME: ${{ steps.build.outputs.pkg }}
run: |
ARTIFACT_TAG=${ARTIFACT_NAME/\~/\_}
release="$(./scripts/gh_release "${{ github.token }}" "${{ github.repository }}" create --draft "${ARTIFACT_TAG}" "${ARTIFACT_COMMIT}" "${ARTIFACT_NAME}")"
tag="gardenlinux/${PKG_NAME#${{ steps.build.outputs.source_name }}_}"
release="$(./scripts/gh_release "${{ github.token }}" "${{ github.repository }}" create --draft "$tag" "${{ github.sha }}" "${{ steps.build.outputs.pkg }}")"
for f in output/*; do
./scripts/gh_release "${{ github.token }}" "${{ github.repository }}" upload "$release" "$f"
done
Expand All @@ -113,6 +114,7 @@ jobs:
- uses: actions/checkout@v4
with:
repository: gardenlinux/package-build
ref: feature/5-remove-pkg-yml
- name: setup binfmt
if: ${{ matrix.arch == 'arm64v8' }}
run: sudo podman run --privileged ghcr.io/gardenlinux/binfmt_container
Expand Down Expand Up @@ -170,6 +172,7 @@ jobs:
- uses: actions/checkout@v4
with:
repository: gardenlinux/package-build
ref: feature/5-remove-pkg-yml
- name: publish drafted release
run: ./scripts/gh_release "${{ github.token }}" "${{ github.repository }}" publish_draft "${{ needs.source.outputs.release }}"
cleanup:
Expand Down
3 changes: 2 additions & 1 deletion container/bin/build_source
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,12 @@ main() (

# Add some meta files next to the created artifacts
echo "$DEB_BUILD_OPTIONS" > .build_options
echo "${pkg}" > .source_name
ln -s "${pkg}_${version}.dsc" .source

# Copy all artifacts to the dedicated output directory
if [ -d "/output" ]; then
{ echo .build_options; echo .source; echo "${pkg}_${version}.dsc"; get_files < "${pkg}_${version}.dsc"; } | while read file; do
{ echo .build_options; echo .source_name; echo .source; echo "${pkg}_${version}.dsc"; get_files < "${pkg}_${version}.dsc"; } | while read file; do
sudo cp -d "$file" "/output/$file"
done
fi
Expand Down
14 changes: 10 additions & 4 deletions scripts/gh_release
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,11 @@ case "$action" in
commit="$1"; shift
name="$1"; shift

normalized_tag=${tag/\~/\_}

release="$(post "releases" '{
"draft": '"$draft"',
"tag_name": "'"$tag"'",
"tag_name": "'"$normalized_tag"'",
"target_commitish": "'"$commit"'",
"name": "'"$name"'"
}' | jq -r '.id')"
Expand All @@ -78,16 +80,20 @@ case "$action" in
release="$1"; shift
asset_file="$1"; shift

asset_name="$(basename "$asset_file")"
normalized_asset_file=${asset_file/\~/\_}

asset_name="$(basename "$normalized_asset_file")"
upload "releases/$release/assets?name=$asset_name" < "$asset_file" > /dev/null
echo "uploaded $asset_file to $release"
echo "uploaded $asset_file to $release ($asset_name)"

;;
"download")
release="$1"; shift
name="$1"; shift

asset_id="$(get "releases/$release/assets" | jq -r '.[] | select(.name == "'"$name"'") | .id')"
normalized_name=${name/\~/\_}

asset_id="$(get "releases/$release/assets" | jq -r '.[] | select(.name == "'"$normalized_name"'") | .id')"
get_binary "releases/assets/$asset_id" > "$name"

;;
Expand Down

0 comments on commit 8530b1e

Please sign in to comment.