Skip to content

Release

Release #55

name: Release and Publish
on:
workflow_dispatch
env:
CARGO_TERM_COLOR: always
jobs:
extract-version:
name: Extract Version
runs-on: ubuntu-latest
outputs:
cargo_version: ${{ steps.extract.outputs.cargo_version }}
steps:
- uses: actions/checkout@v4
- name: Extract version from Cargo.toml
id: extract
run: |
version=$(grep '^version =' Cargo.toml | sed 's/version = "//' | sed 's/"//')
echo "Extracted version: $version"
if [ -z "$version" ]; then
echo "Error: Version is blank."
exit 1
fi
echo "### Release Build: v$version" >> $GITHUB_STEP_SUMMARY
echo "cargo_version=$version" >> $GITHUB_OUTPUT
get-artifact-json:
name: Get Artifact JSON
runs-on: ubuntu-latest
outputs:
artifact_json: ${{ steps.get-json.outputs.artifact_json }}
steps:
- id: get-json
run: |
response=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" "https://api.github.com/repos/${{ github.repository }}/actions/artifacts")
echo "artifact_json=$response" >> $GITHUB_OUTPUT
define-build-matrix:
name: Define Build Matrix
runs-on: ubuntu-latest
needs: [extract-version, get-artifact-json]
outputs:
matrix: ${{ steps.set-matrix.outputs.build_matrix }}
steps:
- name: Set matrix
id: set-matrix
run: |
response = ${{ needs.get-artifact-json.outputs.artifact_json }}
artifact_name="paseto_cli-linux-x64"
artifact_info=$(echo "$response" | jq -r '.artifacts[] | select(.name=="'"$artifact_name"'")')
if [ -n "$artifact_info" ]; then
workflow_run_id=$(echo "$artifact_info" | jq -r '.workflow_run.id')
echo "Artifact $artifact_name already exists from workflow id: $workflow_run_id."
echo 'linux-x64={os: "ubuntu-latest",exists:true, run_id:"$workflow_run_id", artifact:"$artifact_name"}' >> $GITHUB_ENV
else
echo "Artifact does not exist."
echo 'linux-x64={os: "ubuntu-latest",exists:false, run_id:"$workflow_run_id", artifact:"$artifact_name"}' >> $GITHUB_ENV
fi
artifact_name="paseto_cli-darwin"
artifact_info=$(echo "$response" | jq -r '.artifacts[] | select(.name=="'"$artifact_name"'")')
if [ -n "$artifact_info" ]; then
workflow_run_id=$(echo "$artifact_info" | jq -r '.workflow_run.id')
echo "Artifact $artifact_name already exists from workflow id: $workflow_run_id."
echo 'darwin={os: "macos-latest",exists:true, run_id:"$workflow_run_id", artifact:"$artifact_name"}' >> $GITHUB_ENV
else
echo "Artifact does not exist."
echo 'darwin={os: "macos-latest",exists:false, run_id:"$workflow_run_id", artifact:"$artifact_name"}' >> $GITHUB_ENV
fi
artifact_name="paseto_cli-win32-x64"
artifact_info=$(echo "$response" | jq -r '.artifacts[] | select(.name=="'"$artifact_name"'")')
if [ -n "$artifact_info" ]; then
workflow_run_id=$(echo "$artifact_info" | jq -r '.workflow_run.id')
echo "Artifact $artifact_name already exists from workflow id: $workflow_run_id."
echo 'win32-x64={os: "windows-latest",exists:true, run_id:"$workflow_run_id", artifact:"$artifact_name"}' >> $GITHUB_ENV
else
echo "Artifact does not exist."
echo 'win32-x64={os: "windows-latest",exists:false, run_id:"$workflow_run_id", artifact:"$artifact_name"}' >> $GITHUB_ENV
fi
shell: bash

Check failure on line 86 in .github/workflows/release_and_publish.yml

View workflow run for this annotation

GitHub Actions / Release and Publish

Invalid workflow file

The workflow is not valid. .github/workflows/release_and_publish.yml (Line: 86, Col: 16): Unrecognized named-value: 'matrix'. Located at position 1 within expression: matrix.arch
echo "build_matrix.${{ matrix.arch }}=" >> $GITHUB_ENV
echo "build_matrix='version:${{ needs.extract-version.outputs.cargo_version }},target:[${{ env.linux-x64 }},${{ env.darwin }},${{ env.win32-x64 }}]'" >> $GITHUB_OUTPUT
build:
name: Build and Package
runs-on: ${{ matrix.target.os }}
needs: define-build-matrix
strategy:
matrix:
target: ${{ fromJSON(needs.define-build-matrix.outputs.build_matrix) }}
steps:
- name: Checkout code
if: matrix.target.exists == 'false'
uses: actions/checkout@v4
- name: Install Rust
if: matrix.target.exists == 'false'
uses: actions-rs/toolchain@v1
with:
toolchain: stable
target: ${{ matrix.target.os == 'ubuntu-latest' && 'x86_64-unknown-linux-gnu' || matrix.target.os == 'macos-latest' && 'x86_64-apple-darwin' || 'x86_64-pc-windows-msvc' }}
override: true
- name: Build
if: matrix.target.exists == 'false'
uses: actions-rs/cargo@v1
with:
command: build
args: --release --target ${{ matrix.target.os == 'ubuntu-latest' && 'x86_64-unknown-linux-gnu' || matrix.target.os == 'macos-latest' && 'x86_64-apple-darwin' || 'x86_64-pc-windows-msvc' }}
- name: Package Binary
if: matrix.target.exists == 'false'
run: |
if [[ "${{ matrix.target.os }}" == "ubuntu-latest" ]]; then
cd target/x86_64-unknown-linux-gnu/release
tar -czf paseto_cli-linux-x64.tar.gz paseto_cli
mv paseto_cli-linux-x64.tar.gz ../../../
elif [[ "${{ matrix.target.os }}" == "macos-latest" ]]; then
cd target/x86_64-apple-darwin/release
tar -czf paseto_cli-darwin.tar.gz paseto_cli
mv paseto_cli-darwin.tar.gz ../../../
elif [[ "${{ matrix.target.os }}" == "windows-latest" ]]; then
cd target/x86_64-pc-windows-msvc/release
7z a -r paseto_cli-win32-x64.zip paseto_cli.exe
powershell -command "Move-Item -Path paseto_cli-win32-x64.zip -Destination ../../../"
fi
shell: bash
- name: Upload Binary
if: matrix.target.exists == 'false'
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.target.artifact_name }}
path: ${{ matrix.target.os == 'ubuntu-latest' && 'paseto_cli-linux-x64.tar.gz' || matrix.target.os == 'macos-latest' && 'paseto_cli-darwin.tar.gz' || 'paseto_cli-win32-x64.zip' }}
compression-level: 9
create-release:
needs: [ build, extract-version ]
runs-on: ubuntu-latest
steps:
- name: Fail if version is blank
run: |
if [ -z "${{ needs.extract-version.outputs.cargo_version }}" ]; then
echo "Error: Version is blank."
exit 1
fi
echo "Cargo version is ${{ needs.extract-version.outputs.cargo_version }}"
- name: Download Artifacts
uses: actions/download-artifact@v4
with:
run-id: ${{ needs.build.outputs.workflow_run_id }}
path: .
- name: Create Release and Upload Release Assets
uses: softprops/action-gh-release@v2
env:
GITHUB_TOKEN: ${{ secrets.RELEASE_TOKEN }}
with:
tag_name: v${{ needs.extract-version.outputs.cargo_version }}
release_name: Release ${{ needs.extract-version.outputs.cargo_version }}
draft: false
prerelease: false
token: ${{ secrets.RELEASE_TOKEN }}
files: |
*.tar.gz
*.zip
publish-npm:
needs: [ create-release, extract-version, build ]
runs-on: ubuntu-latest
steps:
- name: Fail if version is blank
run: |
if [ -z "${{ needs.extract-version.outputs.cargo_version }}" ]; then
echo "Error: CARGO_VERSION is blank."
exit 1
fi
echo "Cargo version is ${{ needs.extract-version.outputs.cargo_version }}"
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
registry-url: 'https://registry.npmjs.org'
- name: Update package.json version
run: |
current_version=$(node -p "require('./package.json').version")
if [ "$current_version" != "${{ needs.extract-version.outputs.cargo_version }}" ]; then
npm version ${{ needs.extract-version.outputs.cargo_version }} --no-git-tag-version
echo "Version updated from $current_version to ${{ needs.extract-version.outputs.cargo_version }}"
else
echo "Version is already $current_version, no update needed"
fi
- name: Using Workflow Run ID
run: |
echo "Downloading artifacts from workflow id: ${{ needs.build.outputs.workflow_run_id }}"
- name: Download Artifacts
uses: actions/download-artifact@v4
with:
run-id: ${{ needs.build.outputs.workflow_run_id }}
path: .
- name: Install dependencies
env:
BINARY_DISTRIBUTION_VERSION: ${{ needs.extract-version.outputs.cargo_version }}
CI: true
run: |
npm install
npm ci
- name: Publish Linux x64 Binary
run: |
mkdir -p paseto_cli-linux-x64/bin
tar -xzf paseto_cli-linux-x64.tar.gz -C paseto_cli-linux-x64/bin
cd paseto_cli-linux-x64
npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Publish macOS x64 Binary
run: |
ls -la
mkdir -p paseto_cli-darwin-x64/bin
tar -xzf paseto_cli-darwin-x64.tar.gz -C paseto_cli-darwin-x64/bin
cd paseto_cli-darwin-x64
npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Publish macOS arm64 Binary
run: |
ls -la
mkdir -p paseto_cli-darwin-arm64/bin
tar -xzf paseto_cli-darwin-arm64.tar.gz -C paseto_cli-darwin-arm64/bin
cd paseto_cli-darwin-arm64
npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Publish Windows x64 Binary
run: |
dir
mkdir -p paseto_cli-windows-x64/bin
unzip paseto_cli-win32-x64.zip -d paseto_cli-windows-x64/bin
cd paseto_cli-windows-x64
npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}