Release (manual) #82
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Release (manual) | |
on: | |
workflow_dispatch: | |
inputs: | |
extension-version: | |
description: 'Extension version to be released' | |
required: true | |
release-notes: | |
description: 'Release notes of the extension' | |
required: true | |
pre-release: | |
type: boolean | |
required: false | |
default: false | |
description: Is a pre-release? | |
env: | |
RELEASE_BRANCH: release/${{ github.event.inputs.extension-version }} | |
GH_ACCESS_TOKEN: ${{ secrets.USER_PAT }}:${{ secrets.PAT }} | |
EXTENSION_NAME: block-wallet-${{ github.event.inputs.extension-version }} | |
EXTENSION_NAME_FF: block-wallet-firefox-${{ github.event.inputs.extension-version }} | |
ARTIFACTS_FOLDER: artifacts | |
S3_PATH: s3://releases.blockwallet.io/extension | |
TARGET_BRANCH: master | |
CYPRESS_CACHE_FOLDER: cypress/cache | |
jobs: | |
validation: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Print user input | |
run: | | |
echo -e extension-version: ${{ github.event.inputs.extension-version }} | |
echo -e pre-release: ${{ github.event.inputs.pre-release }} | |
echo -e release-notes: ${{ github.event.inputs.release-notes }} | |
- name: Parse and validate extension version string | |
id: semver_extension | |
uses: booxmedialtd/ws-action-parse-semver@v1 | |
with: | |
input_string: ${{ github.event.inputs.extension-version }} | |
version_extractor_regex: 'v(.*)$' | |
- name: Validate release notes is a valid JSON | |
env: | |
DATA: '${{ github.event.inputs.release-notes }}' | |
READ_ONLY: 1 | |
run: | | |
wget https://raw.githubusercontent.com/block-wallet/release-helpers/main/validate_release_notes_and_convert_to_markdown.py -O validate_release_notes_and_convert_to_markdown.py | |
python3 validate_release_notes_and_convert_to_markdown.py | |
- name: Validate the extension version | |
run: | | |
if [[ "${{ steps.semver_extension.outputs.prerelease }}" != "" || "${{ steps.semver_extension.outputs.build }}" != "" ]] | |
then | |
echo "The release must follow the notation MAJOR.MINOR.PATCH without pre-release or build metadata." | |
exit 1 | |
fi | |
if: ${{ github.event.inputs.pre-release == 'false' }} | |
- name: Install semver package | |
run: | | |
wget -O /usr/local/bin/semver \https://raw.githubusercontent.com/block-wallet/release-helpers/main/semver | |
chmod +x /usr/local/bin/semver | |
- name: Check out code | |
uses: actions/checkout@v3 | |
with: | |
token: ${{ secrets.PAT }} | |
ref: ${{ env.GITHUB_REF_NAME }} | |
- name: Compare release version with the latest tag | |
id: tag_comparison | |
run: | | |
git fetch --all --tags | |
latest_tag=$(git tag -l | tail -n 1) | |
if [[ -z $latest_tag ]] | |
then | |
exit 0 | |
fi | |
result=$(semver compare ${{github.event.inputs.extension-version}} $latest_tag) | |
if [[ "$result" != "1" ]] | |
then | |
echo "The proposed tag for the release \"v${{ steps.semver_extension.outputs.fullversion }}\" is not greater than the latest one \"$latest_tag\"" | |
exit 1 | |
fi | |
build: | |
needs: validation | |
runs-on: ubuntu-latest | |
outputs: | |
version_without_preffix: ${{ steps.remove_preffix.outputs.version }} | |
steps: | |
- name: Check out code | |
uses: actions/checkout@v3 | |
with: | |
token: ${{ secrets.PAT }} | |
ref: ${{ env.TARGET_BRANCH }} | |
- name: Remove preffix from the extension version | |
id: remove_preffix | |
run: | | |
updated_version=${{ github.event.inputs.extension-version }} | |
echo $updated_version | |
updated_version=$(echo ${updated_version:1}) | |
echo "::set-output name=version::$updated_version" | |
- name: Initialize mandatory git config | |
run: | | |
git config --global user.name release_process | |
git config --global user.email [email protected] | |
git config --global url.https://[email protected]/.insteadOf https://github.com/ | |
- name: Create release branch | |
run: | | |
existed_in_remote=$(git ls-remote --heads origin ${RELEASE_BRANCH}) | |
if [[ ${existed_in_remote} ]]; then | |
echo "Deleting the branch \"$RELEASE_BRANCH\" to continue with the release" | |
git push origin --delete $RELEASE_BRANCH | |
fi | |
git checkout -b $RELEASE_BRANCH | |
git push -u origin $RELEASE_BRANCH | |
- name: Update new version | |
env: | |
VERSION: ${{ steps.remove_preffix.outputs.version }} | |
run: | | |
wget https://raw.githubusercontent.com/block-wallet/release-helpers/main/update_file.py -O update_file.py | |
FILE=package.json python3 update_file.py | |
FILE=manifest/base.json python3 update_file.py | |
- name: Update release notes | |
env: | |
VERSION: ${{ steps.remove_preffix.outputs.version }} | |
DATA: '${{ github.event.inputs.release-notes }}' | |
run: | | |
FILE=release-notes.json python3 update_file.py | |
rm update_file.py | |
- name: Commit package.json, manifest.json and release-notes.json | |
id: version_commit | |
run: | | |
git add package.json release-notes.json manifest/base.json | |
git commit --message "chore: update files with the new version ${{ github.event.inputs.extension-version }} and also add the new release notes" | |
git push origin $RELEASE_BRANCH | |
- name: Install node | |
uses: actions/setup-node@v3 | |
with: | |
node-version-file: .nvmrc | |
registry-url: https://npm.pkg.github.com | |
- name: Install yarn | |
run: | | |
npm install --global yarn | |
- name: Dependency UI cache | |
uses: actions/cache@v3 | |
with: | |
path: 'packages/ui/node_modules' | |
key: ${{ runner.os }}-modules-v1-${{ hashFiles('packages/ui/yarn.lock') }} | |
- name: Dependency Background cache | |
uses: actions/cache@v3 | |
with: | |
path: 'packages/background/node_modules' | |
key: ${{ runner.os }}-modules-v1-${{ hashFiles('packages/background/yarn.lock') }} | |
- name: Dependency Provider cache | |
uses: actions/cache@v3 | |
with: | |
path: 'packages/provider/node_modules' | |
key: ${{ runner.os }}-modules-v1-${{ hashFiles('packages/provider/yarn.lock') }} | |
- name: Install packages dependencies | |
run: | | |
make install/ci | |
env: | |
GITHUB_TOKEN: ${{ secrets.PAT }} | |
- name: Build extension | |
env: | |
CI: false | |
run: | | |
make build/prod | |
- name: Save extension folder | |
uses: actions/upload-artifact@v3 | |
with: | |
name: blockwallet-extension | |
if-no-files-found: error | |
path: dist | |
- name: Save Firefox extension folder | |
uses: actions/upload-artifact@v3 | |
with: | |
name: blockwallet-extension-firefox | |
if-no-files-found: error | |
path: dist-firefox | |
#tests: | |
# needs: build | |
# container: cypress/browsers:node16.16.0-chrome105-ff99-edge | |
# runs-on: ubuntu-latest | |
# env: | |
# WIDTH: 357 | |
# HEIGHT: 610 | |
# DBUS_SESSION_BUS_ADDRESS: /dev/null | |
# steps: | |
# - name: Checkout e2e repository | |
# uses: actions/checkout@v3 | |
# with: | |
# repository: block-wallet/e2e-tests | |
# ref: refs/heads/main | |
# token: ${{ secrets.PAT }} | |
# - name: Install node | |
# uses: actions/setup-node@v3 | |
# with: | |
# node-version-file: .nvmrc | |
# - name: Install yarn | |
# run: | | |
# npm install --global yarn | |
# - name: Cache e2e dependencies | |
# id: cache-cypress | |
# uses: actions/cache@v3 | |
# with: | |
# path: | | |
# node_modules | |
# cypress/cache | |
# key: ${{ runner.os }}-cypress-v1-${{ hashFiles('yarn.lock') }} | |
# - name: Download the extension | |
# uses: actions/download-artifact@v3 | |
# with: | |
# name: blockwallet-extension | |
# path: blockwallet-extension | |
# - name: Install e2e dependencies | |
# run: | | |
# yarn install --prefer-offline --frozen-lockfile --network-concurrency 1 | |
# - name: UI Tests - Chrome | |
# run: | | |
# yarn run test:e2e | |
# env: | |
# ETHERSCAN_KEY: ${{ secrets.ETHERSCAN_KEY }} | |
# GITHUB_TOKEN: ${{ secrets.PAT }} | |
# TEST_TAGS: puppeteer,extension | |
# - name: Take the release notes screenshot | |
# run: | | |
# yarn run test:e2e | |
# env: | |
# EXTENSION_VERSION: ${{ needs.build.outputs.version_without_preffix }} | |
# TEST_TAGS: release-notes | |
# BROWSER_WIDTH: ${{ env.WIDTH }} | |
# BROWSER_HEIGHT: ${{ env.HEIGHT }} | |
# - name: Install ImageMagick (needed for convert) | |
# run: | | |
# apt update && apt install -y imagemagick --fix-missing | |
# - name: Cut the screenshot | |
# run: | | |
# convert screenshots/release-notes-${{ needs.build.outputs.version_without_preffix }}.png -crop ${{ env.WIDTH }}x${{ env.HEIGHT }}+0+0 $EXTENSION_NAME.png | |
# - name: Save screenshot of release notes | |
# uses: actions/upload-artifact@v3 | |
# with: | |
# name: screenshot | |
# if-no-files-found: error | |
# path: ${{ env.EXTENSION_NAME }}.png | |
package: | |
needs: build | |
runs-on: ubuntu-latest | |
steps: | |
- name: Delete artifacts folders | |
run: | | |
rm -rf screenshot | |
rm -rf blockwallet-extension | |
- name: Download the extension built folder | |
uses: actions/download-artifact@v3 | |
with: | |
name: blockwallet-extension | |
path: blockwallet-extension | |
- name: Download the extension built folder | |
uses: actions/download-artifact@v3 | |
with: | |
name: blockwallet-extension-firefox | |
path: blockwallet-extension-firefox | |
#- name: Download the extension screenshot (release notes) | |
# uses: actions/download-artifact@v3 | |
# with: | |
# name: screenshot | |
# path: screenshot | |
- name: Zip extension | |
id: zip | |
shell: bash | |
run: | | |
mkdir -p $ARTIFACTS_FOLDER | |
mv blockwallet-extension dist | |
mv blockwallet-extension-firefox dist-firefox | |
zip -r -D $ARTIFACTS_FOLDER/$EXTENSION_NAME.zip dist/* | |
cd dist-firefox | |
zip -r -D $EXTENSION_NAME_FF.zip * | |
mv $EXTENSION_NAME_FF.zip ../$ARTIFACTS_FOLDER | |
- name: Calculate SHA of the extension | |
id: sha | |
run: | | |
cd $ARTIFACTS_FOLDER | |
sha256sum $EXTENSION_NAME.zip > $EXTENSION_NAME.checksum | |
sha256sum $EXTENSION_NAME_FF.zip > $EXTENSION_NAME_FF.checksum | |
- name: Configure AWS credentials | |
uses: aws-actions/configure-aws-credentials@v2 | |
with: | |
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID_RELEASE_BUCKET }} | |
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY_RELEASE_BUCKET }} | |
aws-region: eu-central-1 | |
- name: Upload to S3 | |
run: | | |
aws s3 cp --recursive $ARTIFACTS_FOLDER $S3_PATH | |
# aws s3 cp screenshot/$EXTENSION_NAME.png $S3_PATH/$EXTENSION_NAME.png | |
- name: Upload version and notes to S3 | |
env: | |
DATA: '${{ github.event.inputs.release-notes }}' | |
run: | | |
echo "{" > version.json | |
echo "\"extension\": \"${{ github.event.inputs.extension-version }}\"," >> version.json | |
echo "\"prerelease\": \"${{ github.event.inputs.pre-release }}\"" >> version.json | |
echo "}" >> version.json | |
aws s3 cp version.json $S3_PATH/version.json | |
wget https://raw.githubusercontent.com/block-wallet/release-helpers/main/validate_release_notes_and_convert_to_markdown.py -O validate_release_notes_and_convert_to_markdown.py | |
python3 validate_release_notes_and_convert_to_markdown.py | |
aws s3 cp notes.md $S3_PATH/notes.md | |
pull_request: | |
outputs: | |
pr_url: ${{ steps.create_pull_request.outputs.pr_url }} | |
needs: package | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
with: | |
token: ${{ secrets.PAT }} | |
- name: Initialize mandatory git config | |
run: | | |
git config --global user.name release_process | |
git config --global user.email [email protected] | |
git config --global url.https://[email protected]/.insteadOf https://github.com/ | |
- name: Create Pull Request | |
id: create_pull_request | |
env: | |
GH_TOKEN: ${{ secrets.PAT }} | |
run: | | |
s3_url=$(echo "${S3_PATH/s3/https}") | |
pr_title="[Automated] Extension release ${{ github.event.inputs.extension-version }}" | |
pr_body=$(echo -e "# PR for release ${{ github.event.inputs.extension-version }}\n\n## Type of change :writing_hand:\n\nClick the correct/s option/s\n\n- [ ] Bug fix (non-breaking change which fixes an issue)\n- [ ] New feature (non-breaking change which adds functionality)\n- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)\n- [ ] This change requires a documentation update\n\n## Manual tests :test_tube:\n\n- [ ] I run the tests and they were succesful\n\n## Artifacts :space_invader:\n\n - [Extension zip]($s3_url/${{ env.EXTENSION_NAME }}.zip)\n - [SHA256 checksum]($s3_url/${{ env.EXTENSION_NAME }}.checksum)\n - [Firefox Extension zip]($s3_url/${{ env.EXTENSION_NAME_FF }}.zip)\n - [SHA256 checksum]($s3_url/${{ env.EXTENSION_NAME_FF }}.checksum)\n\n") | |
pr_reviewer="block-wallet/releasereviewers" | |
pr_assignee="sreblock" | |
pr_label="automated,release" | |
gh label create --force "automated" --description "PR made by an automation" --color "bcf5db" | |
gh label create --force "release" --description "Extension release" --color "0e8a16" | |
gh pr create \ | |
--base "$TARGET_BRANCH" \ | |
--head "$RELEASE_BRANCH" \ | |
--title "$pr_title" \ | |
--label "$pr_label" \ | |
--reviewer "$pr_reviewer" \ | |
--body "$pr_body" \ | |
--assignee "$pr_assignee" \ | |
--no-maintainer-edit \ | |
--draft | |
sleep 5 | |
url=$(gh pr list --state open --label "$pr_label" --base "$TARGET_BRANCH" --head "$RELEASE_BRANCH" --json url | jq ".[0].url" | tr -d '"') | |
echo "::set-output name=pr_url::$url" | |
notify: | |
if: success() | |
needs: [validation, build, package, pull_request] | |
runs-on: ubuntu-latest | |
steps: | |
- name: Slack notification - Ready to release | |
uses: 8398a7/action-slack@v3 | |
with: | |
status: custom | |
fields: repo,workflow | |
github_token: ${{ secrets.PAT }} | |
custom_payload: | | |
{ | |
"text": "*Release (manual)* for ${{ github.event.inputs.extension-version }} finished.", | |
"attachments": [ | |
{ | |
"color": "good", | |
"pretext": "The pull request was created. After reviewing it, please merge it to continue the release process that will launch *Release (automated)*.", | |
"author_name": "GitHub Pull Request ${{ github.event.inputs.extension-version }}", | |
"author_link": "${{ needs.pull_request.outputs.pr_url }}", | |
"title": "GitHub Pull Request for the release ${{ github.event.inputs.extension-version }} created as draft" | |
} | |
] | |
} | |
env: | |
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_BLOCKWALLET_RELEASES }} | |
error: | |
if: failure() | |
needs: [validation, build, package, pull_request, notify] | |
runs-on: ubuntu-latest | |
steps: | |
- name: Slack notification - CI status | |
uses: 8398a7/action-slack@v3 | |
with: | |
status: failure | |
fields: workflow | |
github_token: ${{ secrets.PAT }} | |
env: | |
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_ALERTS_RELEASES }} |