fixup! ci: Build static executable and docker image on aarch64 via nix #2669
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
name: CI | |
on: | |
push: | |
branches: | |
- main | |
- v[0-9]+ | |
- test | |
tags: | |
- v* | |
concurrency: | |
# Terminate all previous runs of the same workflow for pull requests | |
group: ci-${{ github.head_ref || github.run_id }} | |
cancel-in-progress: true | |
jobs: | |
docs: | |
name: Docs | |
uses: ./.github/workflows/docs.yaml | |
test: | |
name: Test | |
uses: ./.github/workflows/test.yaml | |
secrets: | |
CACHIX_AUTH_TOKEN: ${{ secrets.CACHIX_AUTH_TOKEN }} | |
build: | |
name: Build | |
uses: ./.github/workflows/build.yaml | |
secrets: | |
CACHIX_AUTH_TOKEN: ${{ secrets.CACHIX_AUTH_TOKEN }} | |
arm: | |
name: Nix - Linux aarch64 static | |
runs-on: | |
- self-hosted | |
- Linux | |
- ARM64 | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Build static executable | |
run: nix-build -A postgrestStatic | |
- name: Save built executable as artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: postgrest-linux-static-aarch64 | |
path: result/bin/postgrest | |
if-no-files-found: error | |
- name: Build Docker image | |
run: nix-build -A docker.image --out-link postgrest-docker-arm64.tar.gz | |
- name: Save built Docker image as artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: postgrest-docker-aarch64 | |
path: postgrest-docker-arm64.tar.gz | |
if-no-files-found: error | |
prepare: | |
name: Release / Prepare | |
if: startsWith(github.ref, 'refs/tags/v') | |
runs-on: ubuntu-latest | |
needs: | |
- docs | |
- test | |
- build | |
- arm | |
outputs: | |
version: ${{ steps.Identify-Version.outputs.version }} | |
isprerelease: ${{ steps.Identify-Version.outputs.isprerelease }} | |
steps: | |
- uses: actions/checkout@v4 | |
- id: Identify-Version | |
name: Identify the version to be released | |
run: | | |
tag_version="${GITHUB_REF##*/}" | |
cabal_version="$(grep -oP '^version:\s*\K.*' postgrest.cabal)" | |
if [ "$tag_version" != "v$cabal_version" ]; then | |
echo "Tagged version ($tag_version) does not match the one in postgrest.cabal (v$cabal_version). Aborting release..." | |
exit 1 | |
else | |
echo "Version to be released is $cabal_version" | |
echo "version=$cabal_version" >> "$GITHUB_OUTPUT" | |
fi | |
if [[ "$cabal_version" != *.*.*.* ]]; then | |
echo "Version is for a full release (version does not have four components)" | |
else | |
echo "Version is for a pre-release (version has four components, e.g., 1.1.1.1)" | |
echo "isprerelease=1" >> "$GITHUB_OUTPUT" | |
fi | |
- name: Identify changes from CHANGELOG.md | |
run: | | |
version="${{ steps.Identify-Version.outputs.version }}" | |
isprerelease="${{ steps.Identify-Version.outputs.isprerelease }}" | |
if [ -n "$isprerelease" ]; then | |
echo "Getting unreleased changes..." | |
sed -n "1,/## Unreleased/d;/## \[/q;p" CHANGELOG.md > CHANGES.md | |
else | |
echo "Full release (no '-' in version), getting changes for version $version ..." | |
sed -n "1,/## \[$version\]/d;/## \[/q;p" CHANGELOG.md > CHANGES.md | |
fi | |
echo "Relevant extract from CHANGELOG.md:" | |
cat CHANGES.md | |
- name: Save CHANGES.md as artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: release-changes | |
path: CHANGES.md | |
if-no-files-found: error | |
github: | |
name: Release / GitHub | |
permissions: | |
contents: write | |
runs-on: ubuntu-latest | |
needs: prepare | |
env: | |
VERSION: ${{ needs.prepare.outputs.version }} | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Download all artifacts | |
uses: actions/download-artifact@v4 | |
with: | |
path: artifacts | |
- name: Create release bundle with archives for all builds | |
run: | | |
find artifacts -type f -iname postgrest -exec chmod +x {} \; | |
mkdir -p release-bundle | |
tar cJvf "release-bundle/postgrest-v$VERSION-linux-static-x64.tar.xz" \ | |
-C artifacts/postgrest-linux-static-x64 postgrest | |
tar cJvf "release-bundle/postgrest-v$VERSION-macos-x64.tar.xz" \ | |
-C artifacts/postgrest-macos-x64 postgrest | |
tar cJvf "release-bundle/postgrest-v$VERSION-freebsd-x64.tar.xz" \ | |
-C artifacts/postgrest-freebsd-x64 postgrest | |
tar cJvf "release-bundle/postgrest-v$VERSION-ubuntu-aarch64.tar.xz" \ | |
-C artifacts/postgrest-ubuntu-aarch64 postgrest | |
zip "release-bundle/postgrest-v$VERSION-windows-x64.zip" \ | |
artifacts/postgrest-windows-x64/postgrest.exe | |
- name: Save release bundle | |
uses: actions/upload-artifact@v4 | |
with: | |
name: release-bundle | |
path: release-bundle | |
if-no-files-found: error | |
- name: Publish release on GitHub | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
isprerelease="${{ needs.prepare.outputs.isprerelease }}" | |
echo "Releasing version v$VERSION on GitHub (isprerelease=$isprerelease)..." | |
gh release delete "v$VERSION" || true | |
gh release create "v$VERSION" \ | |
-F artifacts/release-changes/CHANGES.md \ | |
${isprerelease:+"--prerelease"} \ | |
release-bundle/* | |
docker: | |
name: Release / Docker Hub | |
runs-on: ubuntu-latest | |
needs: | |
- prepare | |
env: | |
GITHUB_COMMIT: ${{ github.sha }} | |
DOCKER_REPO: postgrest | |
DOCKER_USER: stevechavez | |
DOCKER_PASS: ${{ secrets.DOCKER_PASS }} | |
VERSION: ${{ needs.prepare.outputs.version }} | |
ISPRERELEASE: ${{ needs.prepare.outputs.isprerelease }} | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Setup Nix Environment | |
uses: ./.github/actions/setup-nix | |
with: | |
authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}' | |
tools: release | |
- name: Download Docker images | |
uses: actions/download-artifact@v4 | |
with: | |
pattern: postgrest-docker-* | |
- name: Publish images on Docker Hub | |
run: | | |
docker login -u "$DOCKER_USER" -p "$DOCKER_PASS" | |
docker load -i postgrest-docker-amd64.tar.gz | |
docker load -i postgrest-docker-arm64.tar.gz | |
docker manifest create \ | |
"$DOCKER_REPO/postgrest:v$VERSION" \ | |
--amend postgrest:x86_64-linux \ | |
--amend postgrest:aarch64-linux | |
docker push "$DOCKER_REPO/postgrest:v$VERSION" | |
# Only tag 'latest' for full releases | |
if [[ -z "$ISPRERELEASE" ]]; then | |
echo "Pushing to 'latest' tag for full release of v$VERSION ..." | |
docker tag "$DOCKER_REPO/postgrest:v$VERSION" "$DOCKER_REPO"/postgrest:latest | |
docker push "$DOCKER_REPO"/postgrest:latest | |
else | |
echo "Skipping pushing to 'latest' tag for v$VERSION pre-release..." | |
fi | |
# TODO: Enable dockerhub description update again, once a solution for the permission problem is found: | |
# https://github.com/docker/hub-feedback/issues/1927 | |
# - name: Update descriptions on Docker Hub | |
# env: | |
# DOCKER_PASS: ${{ secrets.DOCKER_PASS }} | |
# run: | | |
# if [[ -z "$ISPRERELEASE" ]]; then | |
# echo "Updating description on Docker Hub..." | |
# postgrest-release-dockerhub-description | |
# else | |
# echo "Skipping updating description for pre-release..." | |
# fi |