Skip to content

chore: update Dockerfile and vcpkg to use latest #70

chore: update Dockerfile and vcpkg to use latest

chore: update Dockerfile and vcpkg to use latest #70

name: release-needle
on:
push:
branches:
- main
workflow_dispatch:
env:
CARGO_TERM_COLOR: always
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.event.repository.name }}
defaults:
run:
shell: bash
working-directory: needle
jobs:
release-please:
runs-on: ubuntu-latest
outputs:
# NOTE: No idea why release-please is running in "manifest" mode, but it is...
tag_name: ${{ steps['release']['outputs']['needle--tag_name'] }}
release_created: ${{ steps['release']['outputs']['needle--release_created'] }}
steps:
# Copied from: https://github.com/andrey-yantsen/plex-api.rs/blob/main/.github/workflows/release.yml#L18
- uses: google-github-actions/release-please-action@v3
id: release
with:
path: needle
release-type: rust
bump-minor-pre-major: true
bump-patch-for-minor-pre-major: true
changelog-types: |
[{"type":"feat","section":"Features","hidden":false},
{"type":"fix","section":"Bug Fixes","hidden":false},
{"type":"chore","section":"Miscellaneous","hidden":false},
{"type":"test","section":"Tests","hidden":true},
{"type":"ci","section":"Continuous Integration","hidden":true},
{"type":"doc","section":"Documentation","hidden":true},
{"type":"refactor","section":"Code Refactoring","hidden":true}]
linux:
runs-on: ubuntu-latest
needs: release-please
if: needs.release-please.outputs.release_created
env:
TAG_NAME: ${{ needs.release-please.outputs.tag_name }}
steps:
- uses: actions/checkout@v3
- uses: Swatinem/rust-cache@v2
- name: Install dependencies
run: |
sudo apt-get install \
pkg-config \
cmake \
libclang-dev \
libfftw3-dev \
libavutil-dev \
libavformat-dev \
libswresample-dev \
libavcodec-dev
- name: Build release version
run: cargo build -v --release
- name: Compress binary
run: cd target/release && tar cvzf needle-$TAG_NAME-linux-amd64.tar.gz needle
- name: Upload binary to the release
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ env.TAG_NAME }}
files: needle/target/release/*.tar.gz
macos:
runs-on: macos-latest
needs: release-please
if: needs.release-please.outputs.release_created
env:
TAG_NAME: ${{ needs.release-please.outputs.tag_name }}
steps:
- uses: actions/checkout@v3
- uses: Swatinem/rust-cache@v2
- name: Install dependencies
run: brew install ffmpeg
- name: Build release version
run: cargo build -v --release
- name: Compress binary
run: cd target/release && tar cvzf needle-$TAG_NAME-macos-amd64.tar.gz needle
- name: Upload binary to the release
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ env.TAG_NAME }}
files: needle/target/release/*.tar.gz
windows:
runs-on: windows-latest
needs: release-please
if: needs.release-please.outputs.release_created
env:
VCPKG_ROOT: ${{ github.workspace }}/vcpkg
VCPKG_DEFAULT_BINARY_CACHE: ${{ github.workspace }}/vcpkg-bincache
TAG_NAME: ${{ needs.release-please.outputs.tag_name }}
steps:
- uses: actions/checkout@v3
- uses: Swatinem/rust-cache@v2
- name: "Create directory '${{ env.VCPKG_DEFAULT_BINARY_CACHE }}'"
run: mkdir -p $VCPKG_DEFAULT_BINARY_CACHE
shell: bash
- name: Install cargo-vcpkg
run: cargo install cargo-vcpkg
# Restore both vcpkg and its artifacts from the GH cache service.
# Taken from here: https://github.com/lukka/CppCMakeVcpkgTemplate/blob/main/.github/workflows/hosted-pure-workflow.yml
- name: Restore vcpkg and its artifacts.
uses: actions/cache@v3
env:
cache-name: cache-vcpkg
with:
path: |
${{ env.VCPKG_ROOT }}
!${{ env.VCPKG_ROOT }}/buildtrees
!${{ env.VCPKG_ROOT }}/packages
!${{ env.VCPKG_ROOT }}/downloads
!${{ env.VCPKG_ROOT }}/installed
key: ${{ runner.os }}-${{ env.cache-name }}-${{ hashFiles( 'needle/Cargo.lock' ) }}
- name: Install dependencies
run: cargo vcpkg --verbose build
shell: bash
- name: Build release version
run: cargo build -v --release --features static
- name: Compress binary (using Powershell)
run: Compress-Archive -Path "$env:GITHUB_WORKSPACE\needle\target\release\needle.exe" -DestinationPath "$env:GITHUB_WORKSPACE\needle-$env:TAG_NAME-windows-amd64.zip"
shell: pwsh
- name: Upload binary to the release
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ env.TAG_NAME }}
files: "*.zip"
publish-crate:
runs-on: ubuntu-latest
needs:
- release-please
- linux
- macos
- windows
if: needs.release-please.outputs.release_created
steps:
- uses: actions/checkout@v3
- name: Install dependencies
run: |
sudo apt-get install \
libfftw3-dev \
libavutil-dev \
libavformat-dev \
libswresample-dev \
libavcodec-dev
- name: Publish needle-rs to crates.io
run: cargo publish
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
build-and-push-tagged-image:
runs-on: ubuntu-latest
needs:
- release-please
if: needs.release-please.outputs.release_created
env:
TAG_NAME: ${{ needs.release-please.outputs.tag_name }}
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v3
- name: Build image
run: docker build . --file Dockerfile --tag $IMAGE_NAME --label "runnumber=${GITHUB_RUN_ID}"
- name: Log in to GH container registry
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u $ --password-stdin
- name: Push image
run: |
IMAGE_ID=ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME
# Change all uppercase to lowercase
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
# Strip git ref prefix from version
VERSION=$(echo "${{ env.TAG_NAME }}" | sed -e 's,.*/\(.*\),\1,')
# Strip "v" prefix from tag name
VERSION=$(echo "${{ env.TAG_NAME }}" | sed -e 's/^v//')
echo IMAGE_ID=$IMAGE_ID
echo VERSION=$VERSION
docker tag $IMAGE_NAME $IMAGE_ID:$VERSION
docker push $IMAGE_ID:$VERSION