diff --git a/.github/workflows/release-tag.yml b/.github/workflows/release-tag.yml new file mode 100644 index 000000000..9466b1b9f --- /dev/null +++ b/.github/workflows/release-tag.yml @@ -0,0 +1,45 @@ +name: Release Ably UI +on: + release: + types: [published] + +jobs: + run-script: + runs-on: ubuntu-latest + permissions: + packages: write + contents: write + steps: + - uses: actions/checkout@v2 + with: + ref: "main" + token: ${{ secrets.REGISTRY_TOKEN }} + - uses: ruby/setup-ruby@v1 + with: + ruby-version: 3.0.0 + bundler-cache: true + - uses: actions/setup-node@v2 + with: + node-version: "12.16.3" + - run: npm install -g yarn + - name: Grant permissions to Scripts + run: | + chmod +x "release.sh" + chmod +x "./scripts/update-dependents.sh" + - name: Release latest Ably UI version + env: + GITHUB_REGISTRY_TOKEN: ${{ secrets.REGISTRY_TOKEN }} + BUNDLE_RUBYGEMS__PKG__GITHUB__COM: "${{ secrets.REGISTRY_USERNAME }}:${{ secrets.REGISTRY_TOKEN }}" + run: | + git config --global user.email "github@action.code" + git config --global user.name "Github Action" + ./release.sh "${GITHUB_REF/refs\/tags\//}" + shell: bash + - name: Create PR on Voltaire and Website + env: + GITHUB_REGISTRY_TOKEN: ${{ secrets.REGISTRY_TOKEN }} + REGISTRY_USERNAME: ${{ secrets.REGISTRY_USERNAME }} + REGISTRY_TOKEN: ${{ secrets.REGISTRY_TOKEN }} + BUNDLE_RUBYGEMS__PKG__GITHUB__COM: "${{ secrets.REGISTRY_USERNAME }}:${{ secrets.REGISTRY_TOKEN }}" + run: "./scripts/update-dependents.sh" + shell: bash diff --git a/README.md b/README.md index bd08e4de0..8bc7c2055 100644 --- a/README.md +++ b/README.md @@ -268,6 +268,14 @@ Then change back `path` to source `source` in the `Gemfile`. If you need to upda Make sure you commit & push your work and remove the [development-specific config](#using-the-development-build-of-ably-ui-in-the-preview-app) before doing this. +You will need to authenticate with the GitHub [NPM registry](https://docs.github.com/en/free-pro-team@latest/packages/using-github-packages-with-your-projects-ecosystem/configuring-npm-for-use-with-github-packages#authenticating-to-github-packages) and [gem registry](https://docs.github.com/en/free-pro-team@latest/packages/using-github-packages-with-your-projects-ecosystem/configuring-rubygems-for-use-with-github-packages#authenticating-with-a-personal-access-token) to publish. + +After the above, you should have: + +- GITHUB_REGISTRY_TOKEN set in your environment (`.npmrc` will read from it) +- you should do registry login as described in the above docs with your GitHub username and password +- a `~/.gem/credentials` file with a `:github: Bearer TOKEN` (replace GITHUB_REGISTRY_TOKEN with your token - interpolation does not work here) + To deploy a review app with your in-progress code, you can use the `pre-release` script: ```bash @@ -376,33 +384,16 @@ Packages are published to the [GitHub private registry](https://github.com/featu Publishing is done by tagging a release in GitHub. This triggers a GitHub action that pushes to the private NPM and gem registries as well as publishing new artefacts in the CDN, with the version taken from the tag of the GitHub release. ⚠️ -#### Local publishing - -You will need to authenticate with the GitHub [NPM registry](https://docs.github.com/en/free-pro-team@latest/packages/using-github-packages-with-your-projects-ecosystem/configuring-npm-for-use-with-github-packages#authenticating-to-github-packages) and [gem registry](https://docs.github.com/en/free-pro-team@latest/packages/using-github-packages-with-your-projects-ecosystem/configuring-rubygems-for-use-with-github-packages#authenticating-with-a-personal-access-token) to publish. - -After the above, you should have: - -- GITHUB_REGISTRY_TOKEN set in your environment (`.npmrc` will read from it) -- you should do registry login as described in the above docs with your GitHub username and password -- a `~/.gem/credentials` file with a `:github: Bearer TOKEN` (replace GITHUB_REGISTRY_TOKEN with your token - interpolation does not work here) - -To publish, run: - -``` -./release.sh VERSION_NUMBER -``` - -This will release the packages, update library & preview app and create & push the commit and tag. +This will trigger GitHub actions in supported apps (currently [Voltaire](http://github.com/ably/voltaire) & [Website](http://github.com/ably/website)) to create a PR with an ably-ui version update. -### Updating dependent apps +**To trigger a release:** -After releasing a version, if you have GITHUB_REGISTRY_TOKEN and GITHUB_REGISTRY_USERNAME (without the @) set, you can run: - -``` -yarn update:all -``` +- Merge your PR into `main`. +- On the Github [Ably-UI](http://github.com/ably/ably-ui) repo, [create a new release](https://github.com/ably/ably-ui/releases/new) tag. +- Create a new tag with the new version number for the release. +- Publish Release. -This will trigger GitHub actions in supported apps to create a PR with an ably-ui version update. +This will release the packages, update library & preview app and create & push the commit & tag, and also create corresponding PRs in Voltaire & Website. ### Running tests diff --git a/release.sh b/release.sh index 8a7cc9516..58785c82c 100755 --- a/release.sh +++ b/release.sh @@ -2,42 +2,11 @@ # See https://coderwall.com/p/fkfaqq/safer-bash-scripts-with-set-euxo-pipefail set -euo pipefail - -echo "Fetching remote for up to date commit history" -git fetch - -if [ $# -ne 1 ]; then - echo $0: "Error: Please provide a valid semver version, ie. ./release.sh 1.2.1" - exit 1 -fi - -BRANCH=$(git branch --show-current) - -if [[ $BRANCH != "main" ]]; then - echo $0: "Error: Releases can only be made from the main branch" - exit 1 -fi - -COMMITS_AHEAD=$(git rev-list main...origin/main --count) - -if [ $COMMITS_AHEAD -gt 0 ]; then - echo $0: "Error: branch origin/main is ahead of your local main" - exit 1 -fi - -if [[ `git status --porcelain --untracked-files=no` ]]; then - echo $0: "Error: you have uncommited changes. A package is created from the filesystem, not git state so it's important to not have uncommited changes." - exit 1 -fi +env VERSION=$1 TAG=v$1 -if git rev-parse "${TAG}" >/dev/null 2>&1; then - echo $0: "Error: ${TAG} already exists" - exit 1 -fi - echo "Install packages, making sure they are up to date" yarn --frozen-lockfile bundle config set --local frozen true @@ -53,12 +22,25 @@ echo -e "module AblyUi\n VERSION = '$VERSION'\nend" > ./lib/ably_ui/version.rb echo "Build the gem" gem build ably-ui.gemspec +echo "Setting up gem credentials..." +set +x +mkdir -p ~/.gem + +cat << EOF > ~/.gem/credentials +--- +:github: Bearer ${GITHUB_REGISTRY_TOKEN} +EOF + +chmod 0600 ~/.gem/credentials +set -x + echo "Push the gem to the registry" gem push --key github \ --host https://rubygems.pkg.github.com/ably \ ably-ui-$VERSION.gem echo "Update Gemfile.lock" +bundle config unset deployment bundle echo "Remove local gem artifact" diff --git a/scripts/update-dependents.sh b/scripts/update-dependents.sh index 99149e736..73ff24012 100755 --- a/scripts/update-dependents.sh +++ b/scripts/update-dependents.sh @@ -2,8 +2,8 @@ set -eou pipefail -if [[ -z $GITHUB_REGISTRY_USERNAME || -z $GITHUB_REGISTRY_TOKEN ]]; then - echo "GITHUB_REGISTRY_USERNAME or GITHUB_REGISTRY_TOKEN are not set, cannot trigger github actions" +if [[ -z $REGISTRY_USERNAME || -z $REGISTRY_TOKEN ]]; then + echo "REGISTRY_USERNAME or REGISTRY_TOKEN are not set, cannot trigger github actions" exit 1 fi @@ -12,7 +12,7 @@ WEBSITE_RESULT=$(curl \ -sS \ -X POST \ -H "Accept: application/vnd.github.github.v3+json" \ - -u "${GITHUB_REGISTRY_USERNAME}:${GITHUB_REGISTRY_TOKEN}" \ + -u "${REGISTRY_USERNAME}:${REGISTRY_TOKEN}" \ https://api.github.com/repos/ably/website/actions/workflows/update-ably-ui.yml/dispatches \ -d '{"ref": "main"}') @@ -30,7 +30,7 @@ VOLTAIRE_RESULT=$(curl \ -sS \ -X POST \ -H "Accept: application/vnd.github.github.v3+json" \ - -u "${GITHUB_REGISTRY_USERNAME}:${GITHUB_REGISTRY_TOKEN}" \ + -u "${REGISTRY_USERNAME}:${REGISTRY_TOKEN}" \ https://api.github.com/repos/ably/voltaire/actions/workflows/update-ably-ui.yml/dispatches \ -d '{"ref": "main"}')