Skip to content

First attempt at a document on idempotency #8890

First attempt at a document on idempotency

First attempt at a document on idempotency #8890

name: PR Preview Deployment
on:
pull_request:
types: [opened, synchronize, reopened]
jobs:
build_and_deploy:
# do not run in forks
if: github.event.pull_request.head.repo.full_name == github.repository
runs-on: ubuntu-latest
concurrency:
group: pr-${{ github.event.pull_request.number || github.event.number }}
cancel-in-progress: true
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: actions/setup-node@v4
with:
node-version: 20
- uses: actions/github-script@v6
with:
script: |
const comments = require('./.github/workflows/scripts/comments.js');
const maybeComment = await comments.get(context, github);
if (maybeComment) {
await comments.update(context, github, maybeComment.id, `🤖 Your PR preview is being built...`);
} else {
await comments.create(context, github, `🤖 Your PR preview is being built...`);
}
- uses: actions/setup-python@v4
with:
python-version: "3.10"
- name: Install DFX
uses: dfinity/setup-dfx@main
- name: Cache icx-asset binary
id: cache-icx-asset-bin
uses: actions/cache@v3
with:
path: sdk/target/release/icx-asset
key: icxassetbin-master
restore-keys: |
icxassetbin-
- name: Install icx-asset
if: steps.cache-icx-asset-bin.outputs.cache-hit != 'true'
run: |
rm -rf sdk
git clone --depth 1 https://github.com/dfinity/sdk.git
cd sdk
cargo build -p icx-asset --release
- name: Add icx-asset to path
run: |
echo "`pwd`/sdk/target/release/" >> $GITHUB_PATH
- name: "Build & Deploy"
run: |
mkdir -p ~/.config/dfx/identity/default
echo $DFX_IDENTITY_PREVIEW | base64 -d > ~/.config/dfx/identity/default/identity.pem
sed -i 's/\\r\\n/\r\n/g' ~/.config/dfx/identity/default/identity.pem
# request preview canister from the pool
pull_number=$(jq --raw-output .pull_request.number "$GITHUB_EVENT_PATH")
pip install ic-py
canister_id=$(python3 .github/workflows/scripts/request-canister.py $pull_number)
# overwrite canister id in dfx.json
echo "{\"portal\":{\"ic\":\"$canister_id\"}}" > canister_ids.json
echo "PREVIEW_CANISTER_ID=$canister_id" >> $GITHUB_ENV
# install and deploy
git submodule update --init
time npm install
export PREVIEW_CANISTER_ID=$canister_id
dfx canister --network ic create --all
time dfx build --network ic portal
dfx canister --network ic install portal --wasm .dfx/ic/canisters/portal/assetstorage.wasm.gz || true
time icx-asset --replica https://icp0.io --pem ~/.config/dfx/identity/default/identity.pem sync $canister_id build
env:
DFX_IDENTITY_PREVIEW: ${{ secrets.DFX_IDENTITY_PREVIEW }}
POOL_CANISTER_ID: ${{ secrets.POOL_CANISTER_ID }}
CONTENTFUL_ACCESS_TOKEN: ${{ secrets.CONTENTFUL_ACCESS_TOKEN }}
CONTENTFUL_HOST: ${{ secrets.CONTENTFUL_HOST }}
CONTENTFUL_SPACE_ID: ${{ secrets.CONTENTFUL_SPACE_ID }}
AIRTABLE_KEY: ${{ secrets.AIRTABLE_SA_PORTAL_SERVICE_ACCOUNT }}
YOUTUBE_API_KEY: ${{ secrets.YOUTUBE_API_KEY }}
SLACK_TOKEN: ${{ secrets.SLACK_TOKEN }}
- name: Report build error
uses: actions/github-script@v6
if: ${{ failure() }}
with:
script: |
const comments = require('./.github/workflows/scripts/comments.js');
const maybeComment = await comments.get(context, github);
if (maybeComment) {
await comments.update(context, github, maybeComment.id, `🤖 Preview build failed.`);
} else {
await comments.create(context, github, `🤖 Preview build failed.`);
}
- uses: actions/github-script@v6
with:
script: |
const comments = require('./.github/workflows/scripts/comments.js');
const maybeComment = await comments.get(context, github);
if (maybeComment) {
await comments.update(context, github, maybeComment.id, `🤖 Here's your preview: https://${process.env.PREVIEW_CANISTER_ID}.icp0.io`);
} else {
await comments.create(context, github, `🤖 Here's your preview: https://${process.env.PREVIEW_CANISTER_ID}.icp0.io`);
}