-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1e3609f
commit a8828fb
Showing
6 changed files
with
185 additions
and
57 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
name: build | ||
on: | ||
workflow_call: | ||
inputs: | ||
repository: | ||
type: string | ||
default: ${{ github.repository }} | ||
ref: | ||
type: string | ||
default: ${{ github.sha }} | ||
build_container: | ||
type: string | ||
default: ghcr.io/gardenlinux/package-build/amd64 | ||
jobs: | ||
source: | ||
outputs: | ||
pkg: ${{ steps.build.outputs.pkg }} | ||
release: ${{ steps.release.outputs.release }} | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
repository: ${{ github.action_repository }} | ||
ref: ${{ github.action_ref }} | ||
- run: mkdir input output | ||
- uses: actions/checkout@v4 | ||
with: | ||
repository: ${{ inputs.repository }} | ||
ref: ${{ inputs.ref }} | ||
path: input | ||
- name: setup binfmt | ||
run: sudo podman run --privileged ghcr.io/gardenlinux/binfmt_container | ||
- name: pull build container | ||
run: podman pull ${{ inputs.build_container }}:amd64 | ||
- name: build | ||
id: build | ||
run: | | ||
pkg="$(podman run --rm -v "$PWD/input:/input" -v "$PWD/output:/output" ${{ inputs.build_container }}:amd64 build_source)" | ||
echo "pkg=$pkg" | tee "$GITHUB_OUTPUT" | ||
- name: check if ${{ env.pkg }} already released | ||
id: check | ||
run: | | ||
if ./gh_release ${{ github.token }} ${{ github.repository }} exists ${{ env.pkg }}; then | ||
echo "skip_release=true" | tee "$GITHUB_OUTPUT" | ||
else | ||
echo "skip_release=false" | tee "$GITHUB_OUTPUT" | ||
fi | ||
- name: draft release and upload source packages | ||
id: release | ||
if: ${{ steps.check.outputs.skip_release != 'true' }} | ||
run: | | ||
release="$(./gh_release ${{ github.token }} ${{ github.repository }} create --draft "${{ steps.build.outputs.pkg }}" "${{ github.sha }}" "${{ steps.build.outputs.pkg }}")" | ||
for f in output/*; do | ||
./gh_release ${{ github.token }} ${{ github.repository }} upload "$release" "$f" | ||
done | ||
echo "release=$release" | tee "$GITHUB_OUTPUT"b |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
#!/bin/bash | ||
|
||
set -eufo pipefail | ||
|
||
token="$1"; shift | ||
repo="$1"; shift | ||
|
||
curl_path="$(which curl)" | ||
|
||
function curl { | ||
$curl_path -f -s -u "token:$token" "$@" | ||
} | ||
|
||
function get { | ||
[ $# = 1 ] | ||
curl -X GET "https://api.github.com/repos/$repo/$1" | ||
} | ||
|
||
function post { | ||
[ $# = 2 ] | ||
curl -X POST "https://api.github.com/repos/$repo/$1" --data "$2" | ||
} | ||
|
||
function patch { | ||
[ $# = 2 ] | ||
curl -X PATCH "https://api.github.com/repos/$repo/$1" --data "$2" | ||
} | ||
|
||
function delete { | ||
[ $# = 1 ] | ||
curl -X DELETE "https://api.github.com/repos/$repo/$1" | ||
} | ||
|
||
function upload { | ||
[ $# = 1 ] | ||
curl -X POST -H "Content-Type: application/octet-stream" "https://uploads.github.com/repos/$repo/$1" --data-binary @- | ||
} | ||
|
||
action="$1"; shift | ||
|
||
case "$action" in | ||
"exists") | ||
tag="$1"; shift | ||
get "releases/tags/$tag" > /dev/null | ||
|
||
;; | ||
"create") | ||
draft=false | ||
if [ "$1" = "--draft" ]; then | ||
draft=true | ||
shift | ||
fi | ||
tag="$1"; shift | ||
commit="$1"; shift | ||
name="$1"; shift | ||
body="$1"; shift | ||
|
||
release="$(post "releases" '{ | ||
"draft": '"$draft"', | ||
"tag_name": "'"$tag"'", | ||
"target_commitish": "'"$commit"'", | ||
"name": "'"$name"'" | ||
}' | jq -r '.id')" | ||
|
||
echo "$release" | ||
|
||
;; | ||
"upload") | ||
release="$1"; shift | ||
asset_file="$1"; shift | ||
|
||
asset_name="$(basename "$asset_file")" | ||
upload "releases/$release/assets?name=$asset_name" < "$asset_file" > /dev/null | ||
echo "uploaded $asset_file to $release" | ||
|
||
;; | ||
"publish_draft") | ||
release="$1"; shift | ||
patch "releases/$release" '{ "draft": false }' | ||
|
||
;; | ||
esac |