From 190f2a12df9459bb6c1840c8d964c3f9b3a14bc2 Mon Sep 17 00:00:00 2001 From: Ruggero Date: Wed, 12 Jul 2023 14:53:07 +0200 Subject: [PATCH] Add preview workflows, enforce changelog update (#5) --- .github/workflows/library-test.yml | 3 + .../workflows/storybook-preview-deploy.yml | 66 +++++++++++++++++++ .../workflows/storybook-preview-remove.yml | 46 +++++++++++++ CHANGELOG.md | 5 ++ 4 files changed, 120 insertions(+) create mode 100644 .github/workflows/storybook-preview-deploy.yml create mode 100644 .github/workflows/storybook-preview-remove.yml diff --git a/.github/workflows/library-test.yml b/.github/workflows/library-test.yml index a895fd384..c36c35da2 100644 --- a/.github/workflows/library-test.yml +++ b/.github/workflows/library-test.yml @@ -55,3 +55,6 @@ jobs: run: yarn lint - name: Check prettier run: yarn prettify + - name: Enforce changelog + if: github.ref != 'refs/heads/main' + uses: dangoslen/changelog-enforcer@v3.3.1 diff --git a/.github/workflows/storybook-preview-deploy.yml b/.github/workflows/storybook-preview-deploy.yml new file mode 100644 index 000000000..62b92d5fc --- /dev/null +++ b/.github/workflows/storybook-preview-deploy.yml @@ -0,0 +1,66 @@ +name: Storybook Preview Deploy + +on: + pull_request: + types: + - labeled + - synchronize + +env: + NODE_VERSION: 16 + NODE_CACHE: "yarn" + +jobs: + deploy-preview: + if: contains(github.event.pull_request.labels.*.name, 'preview') + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v3.5.3 + - name: Setup Node + uses: actions/setup-node@v3.6.0 + with: + node-version: ${{ env.NODE_VERSION }} + cache: ${{ env.NODE_CACHE }} + - name: Install dependencies + run: yarn install --frozen-lockfile + - name: Build storybook + run: yarn build:storybook + - name: Get previous deployment + uses: peter-evans/find-comment@v2.4.0 + id: get-deployment + with: + issue-number: ${{ github.event.pull_request.number }} + body-includes: "Storybook IPFS Hash: " + - name: Setup Python + uses: actions/setup-python@v4.6.1 + with: + python-version: "3.x" + architecture: "x64" + - name: Install pyyaml + run: pip install --user pyyaml packaging + - name: Install ipfs-cluster-ctl + run: | + wget https://dist.ipfs.io/ipfs-cluster-ctl/v1.0.0/ipfs-cluster-ctl_v1.0.0_linux-amd64.tar.gz + tar xvfz ipfs-cluster-ctl_v1.0.0_linux-amd64.tar.gz + - name: Unpin from IPFS + continue-on-error: true + if: steps.get-deployment.outputs.comment-id != 0 + run: | + COMMENT='${{ steps.get-deployment.outputs.comment-body }}' + IFS=" " read -ra array <<< "$COMMENT" + hash=${array[3]} + ./ipfs-cluster-ctl/ipfs-cluster-ctl --basic-auth '${{ secrets.IPFS_BASIC_AUTH }}' --host '${{ secrets.IPFS_HOST }}' pin rm $hash + - name: Pin on IPFS + id: ipfs-pin + run: | + ipfsResult="$(./ipfs-cluster-ctl/ipfs-cluster-ctl --basic-auth '${{ secrets.IPFS_BASIC_AUTH }}' --host '${{ secrets.IPFS_HOST }}' add -r './storybook-static' | tail -1)" + IFS=" " read -ra array <<< "$ipfsResult" + echo "hash=${array[1]}" >> $GITHUB_OUTPUT + - name: Echo url + uses: peter-evans/create-or-update-comment@v2 + with: + issue-number: ${{ github.event.pull_request.number }} + body: | + Storybook IPFS Hash: ${{ steps.ipfs-pin.outputs.hash }} + ODS deployed to https://ipfs.eth.aragon.network/ipfs/${{ steps.ipfs-pin.outputs.hash }}/ diff --git a/.github/workflows/storybook-preview-remove.yml b/.github/workflows/storybook-preview-remove.yml new file mode 100644 index 000000000..1fa145e8a --- /dev/null +++ b/.github/workflows/storybook-preview-remove.yml @@ -0,0 +1,46 @@ +name: Storybook Preview Remove + +on: + pull_request: + types: + - unlabeled + - closed + +env: + NODE_VERSION: 16 + NODE_CACHE: "yarn" + +jobs: + remove-preview: + if: contains(github.event.pull_request.labels.*.name, 'preview') || github.event.label.name == 'preview' + runs-on: ubuntu-latest + steps: + - name: Install pyyaml + run: pip install --user pyyaml packaging + - name: Install ipfs-cluster-ctl + run: | + wget https://dist.ipfs.io/ipfs-cluster-ctl/v1.0.0/ipfs-cluster-ctl_v1.0.0_linux-amd64.tar.gz + tar xvfz ipfs-cluster-ctl_v1.0.0_linux-amd64.tar.gz + - name: Get deployment + uses: peter-evans/find-comment@v2.4.0 + id: get-deployment + with: + issue-number: ${{ github.event.pull_request.number }} + body-includes: "Storybook IPFS Hash: " + - name: Unpin from IPFS + if: steps.get-deployment.outputs.comment-id != 0 + run: | + COMMENT='${{ steps.get-deployment.outputs.comment-body }}' + IFS=" " read -ra array <<< "$COMMENT" + hash=${array[3]} + ./ipfs-cluster-ctl/ipfs-cluster-ctl --basic-auth '${{ secrets.IPFS_BASIC_AUTH }}' --host '${{ secrets.IPFS_HOST }}' pin rm $hash + - name: Delete Comment + uses: actions/github-script@v6.4.1 + if: steps.get-deployment.outputs.comment-id != 0 + with: + script: | + github.rest.issues.deleteComment({ + comment_id: ${{ steps.get-deployment.outputs.comment-id }}, + owner: context.repo.owner, + repo: context.repo.repo, + }) diff --git a/CHANGELOG.md b/CHANGELOG.md index 103a96f89..ca0c8285a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added + +- Workflows to deploy Storybook previews +- Step to enforce updates to changelog file + ## [0.2.3] - 2023-07-12 ### Fixed