Skip to content

add lock for concurrently writing to map #935

add lock for concurrently writing to map

add lock for concurrently writing to map #935

name: TON - Publish contract artifacts release
# This is a custom temporary solution to get the contract build artifacts on other repos and workflows
permissions:
contents: read
on:
push:
branches: [ main ]
pull_request:
workflow_dispatch:
inputs:
create_release:
description: "Publish a GitHub release on this manual run?"
type: boolean
default: false
required: false
sha:
description: "Commit SHA to build/release (optional)"
type: string
required: false
jobs:
changes:
name: Detect changes
runs-on: ubuntu-latest
outputs:
ton_changes: ${{ steps.changes.outputs.ton_changes }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
persist-credentials: false
- name: Detect changes
id: changes
uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36 # v3.0.2
with:
list-files: "shell"
filters: |
ton_changes:
- 'contracts/**'
- '.github/workflows/contracts-build.yml'
publish:
name: Build Nix pkg and publish tarball
needs: [ changes ]
if: ${{ needs.changes.outputs.ton_changes == 'true' || github.event_name == 'workflow_dispatch' }}
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Check out code
uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4
with:
fetch-depth: 0
- name: Get Long and Short SHAs
id: get_sha
run: |
set -euo pipefail
TARGET_SHA="${{ github.event_name == 'workflow_dispatch' && github.event.inputs.sha != '' && github.event.inputs.sha || github.sha }}"
FULL_SHA="$(git rev-parse "${TARGET_SHA}")"
{
echo "short_sha=${FULL_SHA:0:12}"
echo "full_sha=${FULL_SHA}"
} >> "$GITHUB_OUTPUT"
- name: Install Nix
uses: cachix/install-nix-action@02a151ada4993995686f9ed4f1be7cfbb229e56f # v31
with:
nix_path: nixpkgs=channel:nixos-unstable
- name: Build contracts (Nix) and capture out path
id: nix_build
run: |
set -euo pipefail
OUT_PATH="$(nix build --print-out-paths .#contracts)"
echo "out_path=${OUT_PATH}" >> "$GITHUB_OUTPUT"
echo "Nix out path: ${OUT_PATH}"
- name: Package from Nix build directory
id: package
run: |
set -euo pipefail
mkdir -p dist
TAR_NAME="ton-contracts-build-${{ steps.get_sha.outputs.short_sha }}.tar.gz"
BUILD_DIR="${{ steps.nix_build.outputs.out_path }}/lib/node_modules/@chainlink/contracts-ton/build"
test -d "${BUILD_DIR}" # hard fail if layout changes
tar -C "${BUILD_DIR}" \
--exclude="examples.*" \
-czf "dist/${TAR_NAME}" .
echo "tar_path=dist/${TAR_NAME}" >> "$GITHUB_OUTPUT"
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: ton-contracts-build-${{ steps.get_sha.outputs.short_sha }}
path: ${{ steps.package.outputs.tar_path }}
if-no-files-found: error
retention-days: 14
- name: Publish Release
if: ${{ (github.event_name == 'push' && github.ref == 'refs/heads/main') || (github.event_name == 'workflow_dispatch' && github.event.inputs.create_release == 'true') }}
uses: softprops/action-gh-release@c95fe1489396fe8a9eb87c0abf8aa5b2ef267fda # v2.2.1
with:
token: ${{ secrets.GITHUB_TOKEN }}
tag_name: ton-contracts-build-${{ steps.get_sha.outputs.short_sha }}
target_commitish: ${{ steps.get_sha.outputs.full_sha }}
name: TON Contracts Build (${{ steps.get_sha.outputs.short_sha }})
draft: false
prerelease: false
files: |
${{ steps.package.outputs.tar_path }}