-
Notifications
You must be signed in to change notification settings - Fork 15
149 lines (141 loc) · 6.46 KB
/
github-actions-release-candidate.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
name: Release Candidate
run-name: ${{ github.actor }} is creating a Release Candidate 🚀
on:
push:
branches:
- master
jobs:
Creating-Release-Candidate:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./playbook
env:
GEM_HOST_API_KEY: ${{ secrets.RUBYGEMS_API_KEY }}
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
steps:
- uses: actions/checkout@v3
- name: 'Enable registry auth'
shell: bash
run: |
echo "//registry.npmjs.org/:_authToken="$(echo -n '${{ secrets.NPM_TOKEN }}')"" >> ~/.npmrc
echo "//npm.powerapp.cloud/:_auth="$(echo -n 'gh-actions:${{ secrets.POWERHOME_NPM_REGISTRY_PASSWORD }}' | base64)"" >> ~/.npmrc
echo "//npm.powerapp.cloud/:always-auth = true" >> .npmrc
- uses: actions/setup-node@v4
with:
node-version: 20.11.0
- name: Ruby Setup
uses: ruby/setup-ruby@v1
with:
bundler-cache: true
- name: Python Setup
uses: actions/setup-python@v4
with:
python-version: '3.9'
- name: Set Git Config
run: |
git config --local user.name "${{ github.actor }}"
git config --local user.email "${{ github.actor }}@users.noreply.github.com"
- name: Grab Current Version and Set New RC Version
id: set-version
run: |
current_npm_version=$(node -pe "require('./package.json').version")
if [[ $current_npm_version == *"-rc."* ]]; then
new_npm_version=$(yarn version --prerelease --preid rc --no-git-tag-version | grep "New version:" | awk '{print $4}')
else
new_npm_version=$(yarn version --preminor --preid rc --no-git-tag-version | grep "New version:" | awk '{print $4}')
fi
new_npm_version=${new_npm_version#v}
new_ruby_version=$(echo $new_npm_version | sed 's/-rc\./.pre.rc./')
echo "new_npm_version=${new_npm_version}" >> $GITHUB_ENV
echo "new_ruby_version=${new_ruby_version}" >> $GITHUB_ENV
- name: Check if version exists and increment if necessary
run: |
max_attempts=100
attempt=0
current_version="${{ env.new_npm_version }}"
while [ $attempt -lt $max_attempts ]; do
if npm view playbook-ui@$current_version version &>/dev/null; then
echo "Version $current_version already exists. Incrementing..."
current_version=$(yarn version --prerelease --preid rc --no-git-tag-version | grep "New version:" | awk '{print $4}')
current_version=${current_version#v}
else
echo "Version $current_version is available."
break
fi
attempt=$((attempt+1))
done
if [ $attempt -eq $max_attempts ]; then
echo "Error: Maximum attempts reached. Unable to find an available version."
exit 1
fi
echo "new_npm_version=${current_version}" >> $GITHUB_ENV
new_ruby_version=$(echo $current_version | sed 's/-rc\./.pre.rc./')
echo "new_ruby_version=${new_ruby_version}" >> $GITHUB_ENV
- name: Update Version.rb
run: |
gem install bundler
bundle
bin/rails pb_release:action[${{env.new_ruby_version}}]
- name: Distribute and Publish (NPM)
run: |
yarn install
bundle
yarn release
npm pack
npm publish --registry https://registry.npmjs.org playbook-ui-${{ env.new_npm_version }}.tgz --tag rc
- name: Distribute and Publish (RubyGems)
run: |
bin/build_gem
gem build lib/playbook_ui_docs.gemspec
rm -rf dist/playbook-doc.js dist/playbook-rails.js dist/app dist/pb_doc_helper.rb dist/menu.yml
gem push playbook_ui-${{ env.new_ruby_version }}.gem --host https://rubygems.org/ --key ${{ env.GEM_HOST_API_KEY }}
gem push playbook_ui_docs-${{ env.new_ruby_version }}.gem --host https://rubygems.org/ --key ${{ env.GEM_HOST_API_KEY }}
- name: Create GitHub Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh release create v${{ env.new_npm_version }} \
--title "Release Candidate v${{ env.new_npm_version }}" \
--notes "This is a release candidate version. Please test thoroughly before promoting to a stable release." \
--prerelease
- name: Leave PR comment
uses: actions/github-script@v6
env:
PR_NUMBER: ${{ github.event.pull_request.number }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
RUBY_GEM_VERSION: ${{ env.new_ruby_version }}
RUBY_GEM_LINK: https://rubygems.org/gems/playbook_ui/versions/${{env.new_ruby_version}}
NPM_VERSION: ${{ env.new_npm_version }}
NPM_LINK: https://www.npmjs.com/package/playbook-ui/v/${{env.new_npm_version}}
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const commitSha = context.payload.head_commit.id;
const commitMessage = context.payload.head_commit.message;
const commitAuthor = context.payload.head_commit.author.name;
const commitUrl = context.payload.head_commit.url;
console.log(`Commit message: ${commitMessage}`);
console.log(`Commit author: ${commitAuthor}`);
console.log(`Commit URL: ${commitUrl}`);
// Get the PR related to this commit using octokit API
const pullRequests = await github.rest.repos.listPullRequestsAssociatedWithCommit({
owner: context.repo.owner,
repo: context.repo.repo,
commit_sha: commitSha
});
if (pullRequests.data.length > 0) {
const pullRequestNumber = pullRequests.data[0].number;
console.log(`Found pull request #${pullRequestNumber} for commit ${commitSha}`);
// Add a comment to the pull request
await github.rest.issues.createComment({
issue_number: pullRequestNumber,
owner: context.repo.owner,
repo: context.repo.repo,
body: `You merged this pr to master branch:
- Ruby Gem: [${{env.RUBY_GEM_VERSION}}](${{env.RUBY_GEM_LINK}})
- NPM: [${{env.NPM_VERSION}}](${{env.NPM_LINK}})`
});
} else {
console.log('No pull request found for this commit');
}