Skip to content

Improve Batch Set error lil bit (#297) #266

Improve Batch Set error lil bit (#297)

Improve Batch Set error lil bit (#297) #266

Workflow file for this run

name: Release version
on:
push:
tags:
- "v*.*.*"
branches:
- main
# The following two branch names can be used to force build a version for development and sharing a patch.
- "*force-npm-publish*"
- "v*.*.*-branch*"
- "release-*"
env:
CARGO_TERM_COLOR: always
jobs:
prepare:
name: Prepare release
runs-on: ubuntu-22.04
outputs:
tag_name: ${{ steps.release_info.outputs.tag_name }}
release_name: ${{ steps.release_info.outputs.release_name }}
release_type: ${{ steps.release_info.outputs.release_type }}
is_tagged: ${{ steps.release_info.outputs.is_tagged }}
release_info: ${{ steps.release_info.outputs.release_info }}
matrix: ${{ steps.set_matrix.outputs.matrix }}
changelog: ${{ steps.build_changelog.outputs.changelog }}
commit_hash: ${{ steps.vars.outputs.hash_short }}
steps:
- name: Checkout sources
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Declare commit hash variable
id: vars
shell: bash
run: |
echo "::set-output name=hash_short::$(git rev-parse --short HEAD)"
- name: Compute release name and tag
id: release_info
run: |
## NOTE: currently `tag_name` and `release_name` are the exact same for all these cases. They can be combined.
if [[ "${GITHUB_REF_NAME}" =~ ^v([0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9]+)?(\.[a-zA-Z0-9]+)?) ]]; then
echo "::set-output name=tag_name::${GITHUB_REF_NAME}"
echo "::set-output name=release_name::${GITHUB_REF_NAME}"
echo "::set-output name=is_tagged::true"
echo "::set-output name=release_type::next" # NOTE: we currently go directly into prod when a tag is released - using 'next' would give us time to review before upgrading the tag.
# echo "::set-output name=release_type::latest"
elif [[ "${GITHUB_REF_NAME}" =~ ^release-([0-9]+\.[0-9]+\.[0-9]+) ]]; then
version=v${BASH_REMATCH[1]}
timestamp=$(date +'%Y%m%d%H%M%S')
short_commit=${{ steps.vars.outputs.hash_short }}
echo "::set-output name=tag_name::${version}-${timestamp}-${short_commit}"
echo "::set-output name=release_name::${version}-${timestamp}-${short_commit}"
echo "::set-output name=is_tagged::false"
echo "::set-output name=release_type::dev"
else
timestamp=$(date +'%Y%m%d%H%M%S')
short_commit=${{ steps.vars.outputs.hash_short }}
echo "::set-output name=tag_name::v2.0.0-${GITHUB_REF_NAME}-${timestamp}-${short_commit}"
echo "::set-output name=release_name::v2.0.0-${GITHUB_REF_NAME}-${timestamp}-${short_commit}"
echo "::set-output name=is_tagged::false"
echo "::set-output name=release_type::dev"
fi
- name: Set matrix
id: set_matrix
# The OS is used for the runner
# The platform is a generic platform name
# The target is used by Cargo
# The arch is either 386, arm64 or amd64
# The svm target platform to use for the binary https://github.com/roynalnaruto/svm-rs/blob/84cbe0ac705becabdc13168bae28a45ad2299749/svm-builds/build.rs#L4-L24
# TODO: fix the builds for the below architectures and add them back to the matrix (see the 'Set new version in Cargo.toml' below for windows issue )
# {"os":"windows-latest", "platform":"win32", "target":"x86_64-pc-windows-msvc", "arch":"amd64", "svm_target_platform":"windows-amd64", "name":"win32-x64-msvc"}
run: |
matrix='[
{"os":"ubuntu-22.04", "platform":"linux", "target":"aarch64-unknown-linux-gnu", "arch":"arm64", "svm_target_platform":"linux-aarch64", "name":"linux-arm64-glibc"},
{"os":"ubuntu-22.04", "platform":"linux", "target":"x86_64-unknown-linux-musl", "arch":"amd64", "svm_target_platform":"linux-amd64", "name":"linux-x64-musl"},
{"os":"macos-latest", "platform":"darwin", "target":"x86_64-apple-darwin", "arch":"amd64", "svm_target_platform":"macosx-amd64", "name":"darwin-x64"},
{"os":"macos-latest", "platform":"darwin", "target":"aarch64-apple-darwin", "arch":"arm64", "svm_target_platform":"macosx-aarch64", "name":"darwin-arm64"}
]'
if [[ "${{ steps.release_info.outputs.is_tagged }}" == "false" ]]; then
# Non-release builds are only for the team, so we don't need to build for windows, or old mac books, or unused arm linux.
matrix=$(echo "$matrix" | jq '[.[] | select(.platform != "win32" and .name != "darwin-x64")]')
fi
matrix=$(echo "$matrix" | jq -c '.') # put it on a single line (compact)
echo "::set-output name=matrix::${matrix}"
- name: Build changelog
id: build_changelog
if: steps.release_info.outputs.is_tagged == 'true'
uses: mikepenz/release-changelog-builder-action@v2
with:
configuration: "./.github/changelog.json"
fromTag: ${{ '' }}
toTag: ${{ steps.release_info.outputs.tag_name }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
release:
name: ${{ matrix.job.target }} (${{ matrix.job.os }})
runs-on: ${{ matrix.job.os }}
defaults:
run:
working-directory: codegenerator
needs: prepare
strategy:
matrix:
job: ${{ fromJSON(needs.prepare.outputs.matrix) }}
steps:
- name: Checkout sources
uses: actions/checkout@v4
- name: Set new version in Cargo.toml
working-directory: codegenerator/cli
shell: bash
run: |
awk -v version="${VERSION:1}" '/^version = "/ {$0 = "version = \"" version "\""} 1' Cargo.toml > Cargo.toml.tmp && mv Cargo.toml.tmp Cargo.toml
env:
VERSION: ${{ needs.prepare.outputs.tag_name }}
- name: Install toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
target: ${{ matrix.job.target }}
override: true
- uses: Swatinem/rust-cache@v1
with:
cache-on-failure: true
- name: Apple M1 setup
if: ${{ matrix.job.target == 'aarch64-apple-darwin' }}
run: |
echo "SDKROOT=$(xcrun -sdk macosx --show-sdk-path)" >> $GITHUB_ENV
echo "MACOSX_DEPLOYMENT_TARGET=$(xcrun -sdk macosx --show-sdk-platform-version)" >> $GITHUB_ENV
- name: Linux ARM setup
if: ${{ matrix.job.target == 'aarch64-unknown-linux-gnu' }}
run: |
sudo apt-get update -y
sudo apt-get install -y gcc-aarch64-linux-gnu
echo "CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc" >> $GITHUB_ENV
- if: ${{ runner.os == 'Linux' }}
uses: awalsh128/cache-apt-pkgs-action@v1
with:
# musl-tools provides musl-gcc
packages: musl-tools
- if: ${{ runner.os == 'Linux' }}
run: rustup target add x86_64-unknown-linux-musl
- name: Build binaries
uses: actions-rs/cargo@v1
env:
SVM_TARGET_PLATFORM: ${{ matrix.job.svm_target_platform }}
with:
command: build
args: --release --bins --target ${{ matrix.job.target }} --manifest-path codegenerator/Cargo.toml
- name: Archive binaries
id: artifacts
env:
PLATFORM_NAME: ${{ matrix.job.platform }}
TARGET: ${{ matrix.job.target }}
ARCH: ${{ matrix.job.arch }}
VERSION_NAME: ${{ needs.prepare.outputs.tag_name }}
run: |
if [ "$PLATFORM_NAME" == "linux" ]; then
tar -czvf "envio_${VERSION_NAME}_${PLATFORM_NAME}_${ARCH}.tar.gz" -C ./target/${TARGET}/release envio
echo "::set-output name=file_name::envio_${VERSION_NAME}_${PLATFORM_NAME}_${ARCH}.tar.gz"
elif [ "$PLATFORM_NAME" == "darwin" ]; then
# We need to use gtar here otherwise the archive is corrupt.
# See: https://github.com/actions/virtual-environments/issues/2619
gtar -czvf "envio_${VERSION_NAME}_${PLATFORM_NAME}_${ARCH}.tar.gz" -C ./target/${TARGET}/release envio
echo "::set-output name=file_name::envio_${VERSION_NAME}_${PLATFORM_NAME}_${ARCH}.tar.gz"
else
cd ./target/${TARGET}/release
7z a -tzip "envio_${VERSION_NAME}_${PLATFORM_NAME}_${ARCH}.zip" envio.exe
mv "envio_${VERSION_NAME}_${PLATFORM_NAME}_${ARCH}.zip" ../../../
echo "::set-output name=file_name::envio_${VERSION_NAME}_${PLATFORM_NAME}_${ARCH}.zip"
fi
shell: bash
- name: Build man page
id: man
if: ${{ matrix.job.target == 'x86_64-unknown-linux-gnu' }}
env:
PLATFORM_NAME: ${{ matrix.job.platform }}
TARGET: ${{ matrix.job.target }}
VERSION_NAME: ${{ needs.prepare.outputs.tag_name }}
run: |
sudo apt-get -y install help2man
help2man -N ./target/${TARGET}/release/envio > envio.1
gzip envio.1
tar -czvf "envio_man_${VERSION_NAME}.tar.gz" envio.1.gz
echo "::set-output name=envio_man::envio_man_${VERSION_NAME}.tar.gz"
shell: bash
# Creates the release for this specific version
- name: Create release
if: steps.release_info.outputs.is_tagged == 'true'
uses: softprops/action-gh-release@v1
with:
name: ${{ needs.prepare.outputs.release_name }}
tag_name: ${{ needs.prepare.outputs.tag_name }}
prerelease: true #always true for now
body: ${{ needs.prepare.outputs.changelog }}
files: |
codegenerator/${{ steps.artifacts.outputs.file_name }}
codegenerator/${{ steps.man.outputs.envio_man }}
- name: Install node
uses: actions/setup-node@v4
with:
node-version: "18.16.0"
registry-url: "https://registry.npmjs.org"
- name: Publish to NPM
shell: bash
env:
TARGET: ${{ matrix.job.target }}
NAME: ${{ matrix.job.name }}
OS: ${{ matrix.job.os }}
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
version: ${{ needs.prepare.outputs.tag_name }}
run: |
cd cli/npm
bin="envio"
node_os=$(echo "${NAME}" | cut -d '-' -f1)
export node_os
node_arch=$(echo "${NAME}" | cut -d '-' -f2)
export node_arch
if [ "${OS}" = "windows-2022" ]; then
export node_pkg="${bin}-windows-${node_arch}"
else
export node_pkg="${bin}-${node_os}-${node_arch}"
fi
mkdir -p "${node_pkg}/bin"
envsubst < package.json.tmpl > "${node_pkg}/package.json"
if [ "${OS}" = "windows-2022" ]; then
bin="${bin}.exe"
fi
cp "../../target/${TARGET}/release/${bin}" "${node_pkg}/bin"
cp ../README.md "${node_pkg}"
cd "${node_pkg}"
npm publish --access public
publish-npm:
name: Publish the base package to NPM
needs:
- "release"
- "prepare"
runs-on: ubuntu-22.04
defaults:
run:
working-directory: codegenerator/cli/npm/envio
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install node
uses: actions/setup-node@v4
with:
node-version: "18.16.0"
registry-url: "https://registry.npmjs.org"
- uses: pnpm/action-setup@v3
with:
version: 8
- name: Publish the package
shell: bash
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
version: ${{ needs.prepare.outputs.tag_name }}
RELEASE_TYPE: ${{ needs.prepare.outputs.release_type}}
run: |
envsubst < ./package.json.tmpl > "package.json"
cat package.json # Leave this here for the sake of debugging bad builds.
cp ../../README.md .
echo "Publishing with tag ${RELEASE_TYPE}"
npm publish --access public --tag ${RELEASE_TYPE}
# TODO: add back the integration tests and work out how to automate this. This has been causing issues previously.
# update-npm-tag:
# if: ${{ needs.prepare.outputs.is_tagged }}
# needs:
# - prepare
# - template-integration-test
# runs-on: ubuntu-22.04
# steps:
# - name: update npm tag
# env:
# NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
# VERSION: ${{ needs.prepare.outputs.tag_name }}
# run: |
# npm dist-tag add envio@${VERSION} next
## NOTE: we no longer need to build/push an image every commit.
# build-and-push:
# name: "build, publish and add docker container for deployment"
# needs:
# - "prepare"
# - "publish-npm"
# runs-on: ubuntu-latest
#
# steps:
# - name: Checkout
# uses: actions/checkout@v4
#
# - name: Set up Docker Buildx
# id: buildx
# uses: docker/setup-buildx-action@master
#
# - name: Cache Docker rescript layers
# uses: actions/cache@v2
# with:
# path: /tmp/.base-template-deployer-docker-rescript-cache
# key: ${{ runner.os }}-base-template-deployer-docker-rescript-cache-${{ github.sha }}
# restore-keys: |
# ${{ runner.os }}-base-template-deployer-docker-rescript-cache-
#
# - name: Cache Docker typescript layers
# uses: actions/cache@v2
# with:
# path: /tmp/.base-template-deployer-docker-ts-cache
# key: ${{ runner.os }}-base-template-deployer-docker-ts-cache-${{ github.sha }}
# restore-keys: |
# ${{ runner.os }}-base-template-deployer-docker-ts-cache-
#
# - name: Log in to Docker Hub
# uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a
# with:
# username: ${{ secrets.DOCKER_USERNAME }}
# password: ${{ secrets.DOCKER_ACCESS_TOKEN }}
#
# - name: Build & push docker image
# uses: docker/build-push-action@v2
# with:
# builder: ${{ steps.buildx.outputs.name }}
# file: ./.github/Dockerfile #this parameter does not take into account the context above
# push: true
# tags: ${{ secrets.DOCKER_USERNAME }}/envio-rescript-pnpm:${{ needs.prepare.outputs.release_name }}
# # tags: ${{ secrets.DOCKER_USERNAME }}/envio:${{ needs.prepare.outputs.release_name }}
# build-args: |
# COMMIT_HASH_ARG= ${{ needs.prepare.outputs.commit_hash }} #used for database name
# ENVIO_VERSION=${{ needs.prepare.outputs.tag_name }}
# cache-from: type=local,src=/tmp/.base-template-deployer-docker-rescript-cache
# cache-to: type=local,dest=/tmp/.base-template-deployer-docker-rescript-cache-new
#
# - name: Build & push type script docker image
# uses: docker/build-push-action@v2
# with:
# builder: ${{ steps.buildx.outputs.name }}
# file: ./.github/Dockerfile.typescript #this parameter does not take into account the context above
# push: true
# tags: ${{ secrets.DOCKER_USERNAME }}/envio-typescript-pnpm:${{ needs.prepare.outputs.release_name }}
# # tags: ${{ secrets.DOCKER_USERNAME }}/envio:${{ needs.prepare.outputs.release_name }}
# build-args: |
# COMMIT_HASH_ARG= ${{ needs.prepare.outputs.commit_hash }} #used for database name
# ENVIO_VERSION=${{ needs.prepare.outputs.tag_name }}
# cache-from: type=local,src=/tmp/.base-template-deployer-docker-ts-cache
# cache-to: type=local,dest=/tmp/.base-template-deployer-docker-ts-cache-new
#
# # Temp fix
# # https://github.com/docker/build-push-action/issues/252
# # https://github.com/moby/buildkit/issues/1896
# - name: Move cache
# run: |
# rm -rf /tmp/.base-template-deployer-docker-rescript-cache
# mv /tmp/.base-template-deployer-docker-rescript-cache-new /tmp/.base-template-deployer-docker-rescript-cache
#
# - name: Move cache typescript
# run: |
# rm -rf /tmp/.base-template-deployer-docker-ts-cache
# mv /tmp/.base-template-deployer-docker-ts-cache-new /tmp/.base-template-deployer-docker-ts-cache