|
| 1 | +name: Manual Publish Release |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + commit-sha: |
| 7 | + description: 'The commit SHA to release from (e.g., 256e888 or full SHA)' |
| 8 | + required: true |
| 9 | + type: string |
| 10 | + dry-run: |
| 11 | + description: 'Dry run - validate without publishing' |
| 12 | + required: false |
| 13 | + type: boolean |
| 14 | + default: false |
| 15 | + |
| 16 | +jobs: |
| 17 | + check-permissions: |
| 18 | + name: Check permissions |
| 19 | + runs-on: ubuntu-latest |
| 20 | + steps: |
| 21 | + - name: Check if user is in application-security team |
| 22 | + uses: actions/github-script@v7 |
| 23 | + with: |
| 24 | + script: | |
| 25 | + const org = 'MetaMask'; |
| 26 | + const team = 'application-security'; |
| 27 | + const actor = context.actor; |
| 28 | +
|
| 29 | + try { |
| 30 | + const { data: membership } = await github.rest.teams.getMembershipForUserInOrg({ |
| 31 | + org: org, |
| 32 | + team_slug: team, |
| 33 | + username: actor, |
| 34 | + }); |
| 35 | +
|
| 36 | + if (membership.state === 'active') { |
| 37 | + console.log(`✓ User ${actor} is a member of @${org}/${team}`); |
| 38 | + } else { |
| 39 | + core.setFailed(`✗ User ${actor} is not an active member of @${org}/${team}`); |
| 40 | + } |
| 41 | + } catch (error) { |
| 42 | + if (error.status === 404) { |
| 43 | + core.setFailed(`✗ User ${actor} is not a member of @${org}/${team}`); |
| 44 | + } else { |
| 45 | + core.setFailed(`Error checking team membership: ${error.message}`); |
| 46 | + } |
| 47 | + } |
| 48 | +
|
| 49 | + validate-commit: |
| 50 | + needs: check-permissions |
| 51 | + name: Validate commit |
| 52 | + runs-on: ubuntu-latest |
| 53 | + outputs: |
| 54 | + FULL_SHA: ${{ steps.get-sha.outputs.FULL_SHA }} |
| 55 | + PACKAGE_NAME: ${{ steps.package-info.outputs.PACKAGE_NAME }} |
| 56 | + PACKAGE_VERSION: ${{ steps.package-info.outputs.PACKAGE_VERSION }} |
| 57 | + steps: |
| 58 | + - name: Checkout repository |
| 59 | + uses: actions/checkout@v4 |
| 60 | + with: |
| 61 | + fetch-depth: 0 |
| 62 | + - name: Get full SHA |
| 63 | + id: get-sha |
| 64 | + run: | |
| 65 | + FULL_SHA=$(git rev-parse ${{ github.event.inputs.commit-sha }}) |
| 66 | + if [ -z "$FULL_SHA" ]; then |
| 67 | + echo "Error: Could not resolve commit SHA: ${{ github.event.inputs.commit-sha }}" |
| 68 | + exit 1 |
| 69 | + fi |
| 70 | + echo "FULL_SHA=$FULL_SHA" >> "$GITHUB_OUTPUT" |
| 71 | + echo "Resolved commit SHA: $FULL_SHA" |
| 72 | + - name: Checkout specific commit |
| 73 | + run: git checkout ${{ steps.get-sha.outputs.FULL_SHA }} |
| 74 | + - name: Show commit details |
| 75 | + run: | |
| 76 | + echo "Commit details:" |
| 77 | + git log -1 --pretty=format:"Author: %an <%ae>%nDate: %ad%nSubject: %s%nBody: %b" ${{ steps.get-sha.outputs.FULL_SHA }} |
| 78 | + - name: Get package info |
| 79 | + id: package-info |
| 80 | + run: | |
| 81 | + PACKAGE_NAME=$(jq -r '.name' package.json) |
| 82 | + PACKAGE_VERSION=$(jq -r '.version' package.json) |
| 83 | + echo "PACKAGE_NAME=$PACKAGE_NAME" >> "$GITHUB_OUTPUT" |
| 84 | + echo "PACKAGE_VERSION=$PACKAGE_VERSION" >> "$GITHUB_OUTPUT" |
| 85 | + echo "Package: $PACKAGE_NAME@$PACKAGE_VERSION" |
| 86 | + - name: Check for existing release |
| 87 | + run: | |
| 88 | + TAG="v${{ steps.package-info.outputs.PACKAGE_VERSION }}" |
| 89 | + if git rev-parse "$TAG" >/dev/null 2>&1; then |
| 90 | + echo "⚠️ Warning: Tag $TAG already exists" |
| 91 | + git log -1 --pretty=format:"Existing tag points to: %H%n" "$TAG" |
| 92 | + else |
| 93 | + echo "✓ Tag $TAG does not exist yet" |
| 94 | + fi |
| 95 | +
|
| 96 | + dry-run-summary: |
| 97 | + needs: validate-commit |
| 98 | + if: github.event.inputs.dry-run == 'true' |
| 99 | + name: Dry run summary |
| 100 | + runs-on: ubuntu-latest |
| 101 | + steps: |
| 102 | + - name: Display dry run summary |
| 103 | + run: | |
| 104 | + echo "## 🔍 Dry Run Summary" |
| 105 | + echo "" |
| 106 | + echo "**Mode:** Dry run (no changes will be made)" |
| 107 | + echo "**Package:** ${{ needs.validate-commit.outputs.PACKAGE_NAME }}@${{ needs.validate-commit.outputs.PACKAGE_VERSION }}" |
| 108 | + echo "**Commit:** ${{ needs.validate-commit.outputs.FULL_SHA }}" |
| 109 | + echo "" |
| 110 | + echo "✓ All validation checks passed" |
| 111 | + echo "ℹ️ To publish this release, run the workflow again with 'Dry run' unchecked" |
| 112 | +
|
| 113 | + publish-release: |
| 114 | + needs: validate-commit |
| 115 | + if: github.event.inputs.dry-run == 'false' |
| 116 | + name: Publish release |
| 117 | + permissions: |
| 118 | + contents: write |
| 119 | + uses: ./.github/workflows/publish-release.yml |
| 120 | + with: |
| 121 | + commit-sha: ${{ needs.validate-commit.outputs.FULL_SHA }} |
| 122 | + slack-icon-url: 'https://raw.githubusercontent.com/MetaMask/action-npm-publish/main/robo.png' |
| 123 | + slack-subteam: 'S042S7RE4AE' |
| 124 | + slack-username: 'MetaMask bot' |
| 125 | + secrets: |
| 126 | + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} |
0 commit comments