Skip to content

Commit

Permalink
Add feature to upload JS source maps (#10)
Browse files Browse the repository at this point in the history
This adds parameters to take source maps and minified url as input. Source maps can be up uploaded and downloaded as Github artifact.
  • Loading branch information
mrunalk authored Jun 13, 2020
1 parent ea6d67c commit 5f02bf2
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 14 deletions.
30 changes: 26 additions & 4 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
name: CI

on: [push]
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
build:
Expand All @@ -13,14 +17,23 @@ jobs:
- name: Build
run: echo Building...

- uses: actions/upload-artifact@v2
with:
name: bundle1.js.map
path: test/bundle1.js.map
- uses: actions/upload-artifact@v2
with:
name: bundle2.js.map
path: test/bundle2.js.map

deploy:
needs: build
runs-on: ubuntu-latest
name: Deploy
steps:
- uses: actions/checkout@v2

- name: Nofity rollbar deploy start
- name: Notify rollbar deploy start
uses: ./
id: rollbar_pre_deploy
with:
Expand All @@ -31,25 +44,34 @@ jobs:
ROLLBAR_ACCESS_TOKEN: ${{ secrets.ROLLBAR_ACCESS_TOKEN }}
ROLLBAR_USERNAME: ${{ github.actor }}

- uses: actions/download-artifact@v2
with:
name: bundle1.js.map
- uses: actions/download-artifact@v2
with:
name: bundle2.js.map

# Print Rollbar's deploy id
- name: Get the Rollbar deploy id
run: echo Deploy created with id ${{ steps.rollbar_pre_deploy.outputs.deploy_id }}

- name: Deploy
run: echo Deploying...

- name: Nofity rollbar deploy succeeded
- name: Notify rollbar deploy succeeded
uses: ./
id: rollbar_post_deploy
with:
environment: 'production'
version: ${{ github.sha }}
status: 'succeeded'
source_map: bundle1.js.map bundle2.js.map
minified_url: https://www.example.com/abc/bundle1.js https://www.example.com/xyz/bundle2.js
env:
ROLLBAR_ACCESS_TOKEN: ${{ secrets.ROLLBAR_ACCESS_TOKEN }}
DEPLOY_ID: ${{ steps.rollbar_pre_deploy.outputs.deploy_id }}
ROLLBAR_USERNAME: ${{ github.actor }}

# Print Rollbar's deploy id
- name: Verify both outputs are the same.
run: if [[ "$START_DEPLOY_ID" != "$FINISH_DEPLOY_ID" ]]; then exit 1; fi
Expand Down
41 changes: 40 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ Optionally set `ROLLBAR_USERNAME` environment variable, usernames can be found a
| `environment` | `true` | | The environment where the deploy is being done. |
| `version` | `true` | | The version being deployed. |
| `status` | `false` | `succeeded` | The status of the deploy. |

| `source_maps` | `false` | | JS source map files. |
| `minified_urls`| `false` | | Minified URLs linked to source maps above |

### Ouputs

Expand Down Expand Up @@ -81,3 +82,41 @@ steps:
ROLLBAR_USERNAME: ${{ github.actor }}
DEPLOY_ID: ${{ steps.rollbar_pre_deploy.outputs.deploy_id }}
```
### Example with JS Source Map
```yaml
jobs:
# This workflow builds source maps
build:
- uses: actions/checkout@v2
- name: npm run build
run: npm run build --prefix templates/static/
- uses: actions/upload-artifact@v2
with:
name: bundle.js.map
path: public/bundle.js.map
- uses: actions/upload-artifact@v2
with:
name: bundle2.js.map
path: public/bundle2.js.map
# This workflow deploys source maps to Rollbar
deploy:
needs: build
steps:
- uses: actions/checkout@v2
- uses: actions/download-artifact@v2
with:
name: bundle.js.map
- uses: actions/download-artifact@v2
with:
name: bundle2.js.map
- name: Rollbar deploy
uses: rollbar/[email protected]
with:
environment: production
version: ${{ github.sha }}
status: succeeded
source_maps: bundle.js.map bundle2.js.map
minified_urls: https://www.example.com/public/bundle.js https://www.example.com/public/bundle2.js
env:
ROLLBAR_ACCESS_TOKEN: ${{ secrets.ROLLBAR_ACCESS_TOKEN }}
```
16 changes: 12 additions & 4 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,22 @@ branding:
icon: 'package'
color: 'blue'
inputs:
environment:
description: 'Environment where is deployed'
environment: # required
description: 'Environment where your code is running. e.g. production'
required: true
version:
version: # required
description: 'Version deployed'
required: true
status:
status: # optional
description: 'Deploy status'
required: false
default: 'succeeded'
source_maps: # optional. You can use upload-artifact and download-artifact actions.
description: 'JavaScript source map files, e.g, bundle.js.map as a Github Artifact.'
required: false
minified_urls: # optional.
description: 'URLs to your minified files without schema'
required: false
outputs:
deploy_id:
description: 'The id of the deploy'
Expand All @@ -24,3 +30,5 @@ runs:
- ${{ inputs.environment }}
- ${{ inputs.version }}
- ${{ inputs.status }}
- ${{ inputs.source_maps }}
- ${{ inputs.minified_urls }}
34 changes: 29 additions & 5 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
#!/bin/bash

ENVIRONMENT=$1
VERSION=$2
STATUS=$3
SOURCE_MAP_FILES=$4
MINIFIED_FILES=$5

# Ensure that the ROLLBAR_ACCESS_TOKEN secret is included
if [[ -z "$ROLLBAR_ACCESS_TOKEN" ]]; then
echo "Set the ROLLBAR_ACCESS_TOKEN env variable."
exit 1
fi

# Ensure that the environment is included
if [[ -z "$1" ]]; then
if [[ -z "$ENVIRONMENT" ]]; then
echo "Missing the environment argument."
exit 1
fi

# Ensure that the version is included
if [[ -z "$2" ]]; then
if [[ -z "$VERSION" ]]; then
echo "Missing the version argument."
exit 1
fi
Expand All @@ -27,9 +33,9 @@ fi

RESPONSE=$(curl -X $METHOD https://api.rollbar.com/api/1/deploy/$DEPLOY_ID \
-H "X-ROLLBAR-ACCESS-TOKEN: $ROLLBAR_ACCESS_TOKEN" \
--form environment=$1 \
--form revision=$2 \
--form status=$3 \
--form environment=$ENVIRONMENT \
--form revision=$VERSION \
--form status=$STATUS \
--form rollbar_username=$ROLLBAR_USERNAME)

# Get the deploy id depending on the response as they are different for POST and PATCH
Expand All @@ -46,3 +52,21 @@ fi

# Done
echo "::set-output name=deploy_id::$ROLLBAR_DEPLOY_ID"

# Source map is provided
if [[ "$SOURCE_MAP_FILES" ]]; then
echo "Uploading source map..."
if [[ "${#SOURCE_MAP_FILES[@]}" -ne "${#MINIFIED_FILES[@]}" ]]; then
echo "Number of source map files and minified files are not same."
exit 1
fi
for i in ${!SOURCE_MAP_FILES[@]}; do
echo "${SOURCE_MAP_FILES[$i]} : ${MINIFIED_FILES[$i]}"
curl -v https://api.rollbar.com/api/1/sourcemap \
-F access_token=$ROLLBAR_ACCESS_TOKEN \
-F version=$VERSION \
-F minified_url=${MINIFIED_FILES[$i]} \
-F source_map=@${SOURCE_MAP_FILES[$i]}
done
fi

1 change: 1 addition & 0 deletions test/bundle1.js.map

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions test/bundle2.js.map

Large diffs are not rendered by default.

0 comments on commit 5f02bf2

Please sign in to comment.