Update crates-io.yml #11
Workflow file for this run
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
on: | |
push: | |
tags: | |
- "pragma-*/v*.*.*" | |
name: "Release on crates.io" | |
jobs: | |
crate-info: | |
name: "Extract crate info" | |
runs-on: "ubuntu-latest" | |
outputs: | |
crate: ${{ steps.derive.outputs.crate }} | |
version: ${{ steps.derive.outputs.version }} | |
steps: | |
- id: "derive" | |
name: "Derive crate info from Git tag" | |
run: | | |
FULL_REF="${{ github.ref }}" | |
REGEX="^refs\/tags\/([a-z\\-]*)\/v(.*)$" | |
[[ $FULL_REF =~ $REGEX ]]; | |
echo "crate=${BASH_REMATCH[1]}" >> $GITHUB_OUTPUT | |
echo "version=${BASH_REMATCH[2]}" >> $GITHUB_OUTPUT | |
# Just in case we accidentally release something not on master. | |
commit-branch-check: | |
name: "Check commit branch" | |
runs-on: "ubuntu-latest" | |
needs: ["crate-info"] | |
steps: | |
- name: "Checkout source code" | |
uses: "actions/checkout@v3" | |
with: | |
fetch-depth: 0 | |
- name: "Check if commit is on main" | |
run: | | |
COMMIT_HASH=$(git log -1 --format=%H ${{ github.ref }}) | |
GREP_OUTPUT=$(git log origin/main --format=%H | grep "$COMMIT_HASH") | |
if [ -z "$GREP_OUTPUT" ]; then | |
echo "Cannot release commits not on the main branch" | |
exit 1 | |
fi | |
crate-version-check: | |
name: "Check crate version" | |
runs-on: "ubuntu-latest" | |
needs: ["crate-info"] | |
steps: | |
- name: "Checkout source code" | |
uses: "actions/checkout@v3" | |
- name: "Check against Cargo.toml" | |
run: | | |
if [ "pragma" != "${{ needs.crate-info.outputs.crate }}" ]; then | |
cd ${{ needs.crate-info.outputs.crate }} | |
fi | |
GREP_OUTPUT=$(cat Cargo.toml | grep "^version = \"${{ needs.crate-info.outputs.version }}\"$") | |
if [ -z "$GREP_OUTPUT" ]; then | |
echo "Crate version mismatch" | |
exit 1 | |
fi | |
build: | |
name: "Build for ${{ matrix.os }}" | |
runs-on: "${{ matrix.os }}" | |
needs: ["crate-info"] | |
strategy: | |
matrix: | |
os: | |
- "ubuntu-latest" | |
- "windows-latest" | |
- "macos-latest" | |
steps: | |
- name: "Checkout source code" | |
uses: "actions/checkout@v3" | |
- name: "Setup stable toolchain" | |
uses: "actions-rs/toolchain@v1" | |
with: | |
toolchain: "stable" | |
profile: "minimal" | |
override: true | |
- name: "Install PostgreSQL (Windows)" | |
if: matrix.os == 'windows-latest' | |
run: | | |
choco install postgresql14 | |
echo "C:\Program Files\PostgreSQL\14\lib" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append | |
echo "C:\Program Files\PostgreSQL\14\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append | |
echo "PQ_LIB_DIR=C:\Program Files\PostgreSQL\14\lib" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append | |
echo "POSTGRES_HOME=C:\Program Files\PostgreSQL\14" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append | |
- name: "Install PostgreSQL dependencies (macOS)" | |
if: matrix.os == 'macos-latest' | |
run: | | |
brew install libpq | |
brew link --force libpq | |
echo 'export PATH="/usr/local/opt/libpq/bin:$PATH"' >> ~/.zshrc | |
export LDFLAGS="-L/usr/local/opt/libpq/lib" | |
export CPPFLAGS="-I/usr/local/opt/libpq/include" | |
- name: "Build crate" | |
run: | | |
cargo build --package ${{ needs.crate-info.outputs.crate }} --all-targets | |
crates-io-release: | |
name: "Release to crates.io" | |
runs-on: "ubuntu-latest" | |
needs: | |
- "crate-info" | |
- "commit-branch-check" | |
- "crate-version-check" | |
- "build" | |
steps: | |
- name: "Checkout source code" | |
uses: "actions/checkout@v3" | |
- name: "Login to crates.io" | |
run: | | |
cargo login ${{ secrets.CRATES_IO_API_TOKEN }} | |
- name: "Public crate" | |
run: | | |
cargo publish --package ${{ needs.crate-info.outputs.crate }} |