Skip to content

Commit ebea19b

Browse files
Add create-package github action support
1 parent 5c59483 commit ebea19b

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

.github/workflows/create-package.yml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: create-package
2+
on:
3+
pull_request:
4+
types: [labeled, unlabeled, synchronize]
5+
jobs:
6+
create-package:
7+
runs-on: ubuntu-latest
8+
if: contains(github.event.pull_request.labels.*.name, 'create-package')
9+
env:
10+
GH_TOKEN: ${{ github.token }}
11+
steps:
12+
- uses: actions/checkout@master
13+
- uses: actions/setup-node@master
14+
with:
15+
node-version: "14.19.0"
16+
# Get a bot token so the bot's name shows up on all our actions
17+
- name: Get Token From roku-ci-token Application
18+
uses: tibdex/github-app-token@v1
19+
id: generate-token
20+
with:
21+
app_id: ${{ secrets.BOT_APP_ID }}
22+
private_key: ${{ secrets.BOT_PRIVATE_KEY }}
23+
- run: echo "TOKEN=${{ steps.generate-token.outputs.token }}" >> $GITHUB_ENV
24+
- name: Compute variables
25+
run: |
26+
CURRENT_VERSION=$(grep -o '\"version\": *\"[^\"]*\"' package.json | awk -F'\"' '{print $4}')
27+
SANITIZED_BRANCH_NAME=$(echo "$GITHUB_HEAD_REF" | sed 's/[^0-9a-zA-Z-]/-/g')
28+
BUILD_VERSION="$CURRENT_VERSION-$SANITIZED_BRANCH_NAME.$(date +%Y%m%d%H%M%S)"
29+
NPM_PACKAGE_NAME=$(grep -o '\"name\": *\"[^\"]*\"' package.json | awk -F'\"' '{print $4}' | sed -e 's/@//g' -e 's#/#-#g')
30+
ARTIFACT_NAME=$(echo "$NPM_PACKAGE_NAME-$BUILD_VERSION.tgz" | tr '/' '-')
31+
ARTIFACT_URL="${{ github.server_url }}/${{ github.repository }}/releases/download/v0.0.0-packages/${ARTIFACT_NAME}"
32+
33+
echo "BUILD_VERSION=$BUILD_VERSION" >> $GITHUB_ENV
34+
echo "ARTIFACT_URL=$ARTIFACT_URL" >> $GITHUB_ENV
35+
36+
- run: npm ci
37+
- run: npm version "$BUILD_VERSION" --no-git-tag-version
38+
- run: npm pack
39+
40+
# create the release if not exist
41+
- run: gh release create v0.0.0-packages --title "v0.0.0-packages" --latest=false --prerelease --notes "catchall release for temp packages" -R ${{ github.repository }}
42+
continue-on-error: true
43+
44+
# upload this artifact to the "packages" github release
45+
- run: gh release upload v0.0.0-packages *.tgz -R ${{ github.repository }}
46+
47+
- name: Fetch build artifact
48+
uses: actions/github-script@v7
49+
with:
50+
github-token: ${{ env.TOKEN }}
51+
script: |
52+
return github.rest.issues.createComment({
53+
issue_number: context.issue.number,
54+
owner: context.repo.owner,
55+
repo: context.repo.repo,
56+
body: "Hey there! I just built a new temporary npm package based on ${{ github.event.pull_request.head.sha }}. You can download it [here](${{ env.ARTIFACT_URL }}) or install it by running the following command: \n```bash\nnpm install ${{ env.ARTIFACT_URL }}\n```"
57+
});

0 commit comments

Comments
 (0)