Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/workflows/build-lint-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ jobs:
is-high-risk-environment: false

- run: yarn lint
- name: Validate RC changelog
if: ${{ startsWith(github.head_ref, 'release/') }}
run: yarn lint:changelog --rc
- name: Validate changelog
if: ${{ !startsWith(github.head_ref, 'release/') }}
run: yarn lint:changelog

- name: Require clean working directory
shell: bash
Expand Down
42 changes: 42 additions & 0 deletions .github/workflows/create-release-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Create Release Pull Request

on:
workflow_dispatch:
inputs:
base-branch:
description: 'The base branch for git operations and the pull request.'
default: 'main'
required: true
release-type:
description: 'A SemVer version diff, i.e. major, minor, or patch. Mutually exclusive with "release-version".'
required: false
release-version:
description: 'A specific version to bump to. Mutually exclusive with "release-type".'
required: false

jobs:
create-release-pr:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout and setup environment
uses: MetaMask/action-checkout-and-setup@v2
with:
is-high-risk-environment: true

# This is to guarantee that the most recent tag is fetched. This can
# be configured to a more reasonable value by consumers.
fetch-depth: 0

# We check out the specified branch, which will be used as the base
# branch for all git operations and the release PR.
ref: ${{ github.event.inputs.base-branch }}

- uses: MetaMask/action-create-release-pr@v4
with:
release-type: ${{ github.event.inputs.release-type }}
release-version: ${{ github.event.inputs.release-version }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
25 changes: 25 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,28 @@ jobs:
if [[ "$PASSED" != "true" ]]; then
exit 1
fi

is-release:
# Filtering by `push` events ensures that we only release from the `main` branch, which is a
# requirement for our npm publishing environment.
# The commit author should always be 'github-actions' for releases created by the
# 'create-release-pr' workflow, so we filter by that as well to prevent accidentally
# triggering a release.
if: github.event_name == 'push' && startsWith(github.event.head_commit.author.name, 'github-actions')
needs: all-jobs-pass
outputs:
IS_RELEASE: ${{ steps.is-release.outputs.IS_RELEASE }}
runs-on: ubuntu-latest
steps:
- uses: MetaMask/action-is-release@v1
id: is-release

publish-release:
needs: is-release
if: needs.is-release.outputs.IS_RELEASE == 'true'
name: Publish release
permissions:
contents: write
uses: ./.github/workflows/publish-release.yml
secrets:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
86 changes: 86 additions & 0 deletions .github/workflows/publish-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
name: Publish Release

on:
workflow_call:
inputs:
slack-icon-url:
required: false
type: string
default: 'https://raw.githubusercontent.com/MetaMask/action-npm-publish/main/robo.png'
slack-subteam:
required: false
type: string
default: S042S7RE4AE # @metamask-npm-publishers
slack-username:
required: false
type: string
default: 'MetaMask bot'
secrets:
SLACK_WEBHOOK_URL:
required: true

jobs:
announce-release:
name: Announce release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- id: name-hash
name: Get Slack name and hash
shell: bash
if: inputs.slack-subteam != ''
run: |
NAME_VERSION_TEXT=$(jq --raw-output '.name + "@" + .version' package.json )
NAME_VERSION_TEXT_STRIPPED="${NAME_VERSION_TEXT#@}"
echo "NAME_VERSION=$NAME_VERSION_TEXT_STRIPPED" >> "$GITHUB_OUTPUT"
- id: final-text
name: Get Slack final text
shell: bash
if: inputs.slack-subteam != ''
run: |
DEFAULT_TEXT="\`${{ steps.name-hash.outputs.NAME_VERSION }}\` is awaiting deployment :rocket: \n <https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}/|→ Click here to review deployment>"
SUBTEAM_TEXT="${{ inputs.slack-subteam }}"
FINAL_TEXT="$DEFAULT_TEXT"
if [[ ! "$SUBTEAM_TEXT" == "" ]]; then
FINAL_TEXT="<!subteam^$SUBTEAM_TEXT> $DEFAULT_TEXT"
fi
echo "FINAL_TEXT=$FINAL_TEXT" >> "$GITHUB_OUTPUT"
- name: Post to a Slack channel
if: inputs.slack-subteam != ''
uses: slackapi/slack-github-action@007b2c3c751a190b6f0f040e47ed024deaa72844
with:
payload: |
{
"text": "${{ steps.final-text.outputs.FINAL_TEXT }}",
"icon_url": "${{ inputs.slack-icon-url }}",
"username": "${{ inputs.slack-username }}"
}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK
continue-on-error: true

publish-release:
name: Publish release
environment: npm-publish
needs: announce-release
permissions:
contents: write
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v5
with:
# This is to guarantee that the most recent tag is fetched, which we
# need for updating the shorthand major version tag.
fetch-depth: 0
ref: ${{ github.sha }}
- name: Publish release
uses: MetaMask/action-publish-release@v3
id: publish-release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Update shorthand major version tag
run: |
./.github/workflows/scripts/update-major-version-tag.sh \
${{ steps.publish-release.outputs.release-version }}
31 changes: 31 additions & 0 deletions .github/workflows/scripts/update-major-version-tag.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env bash

set -x
set -e
set -o pipefail

RELEASE_VERSION="${1}"

if [[ -z $RELEASE_VERSION ]]; then
echo "Error: No release version specified."
exit 1
fi

MAJOR_VERSION_TAG="v${RELEASE_VERSION/\.*/}"

git config user.name github-actions
git config user.email github-actions@github.com

if git show-ref --tags "$MAJOR_VERSION_TAG" --quiet; then
echo "Tag \"${MAJOR_VERSION_TAG}\" exists, attempting to delete it."
git tag --delete "$MAJOR_VERSION_TAG"
git push --delete origin "$MAJOR_VERSION_TAG"
else
echo "Tag \"${MAJOR_VERSION_TAG}\" does not exist, creating it from scratch."
fi

git tag "$MAJOR_VERSION_TAG" HEAD
git push --tags
echo "Updated shorthand major version tag."

echo "MAJOR_VERSION_TAG=$MAJOR_VERSION_TAG" >> "$GITHUB_OUTPUT"
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

[Unreleased]: https://github.com/MetaMask/github-tools/
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,18 @@
"version": "0.0.0",
"private": true,
"description": "Tools for interacting with the GitHub API to do metrics gathering",
"repository": {
"type": "git",
"url": "https://github.com/MetaMask/github-tools.git"
},
"scripts": {
"changelog:check": "ts-node src/changelog-check.ts",
"count-references-to-contributor-docs": "ts-node --swc src/scripts/count-references-to-contributor-docs/cli.ts",
"gen:commits": "node .github/scripts/generate-rc-commits.mjs",
"get-review-metrics": "ts-node src/get-review-metrics.ts",
"lint": "yarn lint:tsc && yarn lint:eslint && yarn lint:constraints && yarn lint:misc --check && yarn lint:dependencies --check",
"lint:constraints": "yarn constraints",
"lint:changelog": "auto-changelog validate --prettier",
"lint:dependencies": "depcheck && yarn dedupe",
"lint:eslint": "eslint . --cache --ext js,ts",
"lint:fix": "yarn lint:eslint --fix && yarn lint:constraints --fix && yarn lint:misc --write && yarn lint:dependencies",
Expand Down
Loading