forked from segmentio/action-destinations
-
Notifications
You must be signed in to change notification settings - Fork 0
93 lines (82 loc) · 3.25 KB
/
version-packages.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# This workflow is triggered manually via the GitHub Actions page or API
name: Version Packages
run-name: Version Packages ${{ github.event.inputs.run_id }}
on:
workflow_dispatch:
inputs:
branch:
description: 'Branch to create PR from'
required: true
default: 'release-actions'
base_branch:
description: 'Base branch to create PR to'
required: true
default: 'main'
type: choice
options:
- main
- release
run_id:
description: 'Unique identifier for the run'
required: false
jobs:
build-and-version-packages:
env:
HUSKY: 0
runs-on: ubuntu-latest
permissions:
pull-requests: write
contents: write
steps:
- name: Echo Inputs
run: |
echo "Branch ${{ github.event.inputs.branch }} will be created from ${{ github.event.inputs.base_branch }} and a PR will be created to ${{ github.event.inputs.base_branch }}"
- uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-tags: true
ref: ${{ github.event.inputs.base_branch }}
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
registry-url: 'https://registry.npmjs.org'
cache: yarn
- name: Checkout branch
run: |
git checkout -b ${{ github.event.inputs.branch }}
git push origin ${{ github.event.inputs.branch }}
- name: Install Dependencies
run: yarn install --frozen-lockfile --ignore-optional
- name: Configure git
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
- name: Build
run: NODE_ENV=production yarn build
- name: Version Packages
run: yarn lerna version minor --allow-branch ${{ github.event.inputs.branch }} --no-git-tag-version --no-commit-hooks --no-private --yes
- name: Commit and push
id: commit_and_push
run: |
git add .
count=$(git diff --cached --stat)
if [ -z "$count" ]; then
echo "No changes to commit"
echo "SKIP_PR=true" >> $GITHUB_OUTPUT
exit 0
fi
packages_published=$(git status -s -uno| grep "package.json" |awk '{print $2}'| xargs jq -r '.name + "@" + .version' --argjson null {})
echo "packages_published<<EOF" >> $GITHUB_OUTPUT
echo "$packages_published" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
git commit -m "Publish"
git push origin ${{ github.event.inputs.branch }}
- name: Create PR
if: ${{ steps.commit_and_push.outputs.SKIP_PR != 'true' }}
run: |
pr_message="This PR was opened by GithHub Actions. Whenever you're ready to publish the packages, merge this PR."
description="$(printf "%s\n # Packages\n%s" "$pr_message" "${{ steps.commit_and_push.outputs.packages_published }}")"
gh pr create --base ${{ github.event.inputs.base_branch }} --head ${{ github.event.inputs.branch }} --title "Publish" --body "$description"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}