Repository navigation
feat: update CI with auto-deploy and auto-incrementing versions #12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jcary741
wants to merge
2
commits into
publisher-production
Choose a base branch
from
ci-auto-release
base: publisher-production
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+142
−8
Open
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| ## Summary | ||
|
|
||
| ## Test plan | ||
|
|
||
| ## Todo | ||
|
|
||
| - [ ] PR title has a `fix:`/`feat:`/`feat!:` prefix (or intentionally none, for no release) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| name: NPM release | ||
|
|
||
| on: | ||
| push: | ||
| branches: ['main'] | ||
| workflow_dispatch: {} | ||
|
|
||
| concurrency: | ||
| group: npm-release-${{ github.ref_name }} | ||
| cancel-in-progress: false | ||
|
|
||
| env: | ||
| CI: true | ||
| bucket: '{ "staging": "labs.mapbox.com-staging/to-color", "production": "labs.mapbox.com/to-color" }' | ||
|
|
||
| permissions: | ||
| id-token: write | ||
| contents: write | ||
| pull-requests: write | ||
|
|
||
| jobs: | ||
| publish: | ||
| name: "Publish ${{ github.ref_name }}" | ||
| runs-on: ubuntu-latest | ||
| # npm's Trusted Publisher config for @mapbox/to-color is bound to this workflow file and environment. | ||
| environment: npm-release | ||
| steps: | ||
| - uses: actions/checkout@v5 | ||
| with: | ||
| fetch-depth: 0 | ||
| persist-credentials: false | ||
|
|
||
| - uses: actions/setup-node@v6 | ||
| with: | ||
| node-version-file: .nvmrc | ||
| cache: npm | ||
|
|
||
| - name: Upgrade npm for OIDC trusted publishing support | ||
| run: npm install -g npm@^11.5.1 | ||
|
|
||
| - name: Install npm dependencies | ||
| run: npm ci --no-fund --no-audit --prefer-offline | ||
|
|
||
| # Runs eslint and jest | ||
| - name: Lint and test | ||
| run: npm test | ||
|
|
||
| # Reads the current version from public npmjs and git history | ||
| - id: version | ||
| uses: mapbox/gha@action-conventional-commit-version-v0 | ||
| with: | ||
| before-sha: ${{ github.event.before }} | ||
| after-sha: ${{ github.event.after }} | ||
|
|
||
| # prepublishOnly builds dist/ | ||
| - name: Publish | ||
| if: steps.version.outputs.skip != 'true' | ||
| run: | | ||
| npm version ${{ steps.version.outputs.version }} --no-git-tag-version | ||
| npm publish --tag ${{ steps.version.outputs.npm_publish_tag }} | ||
|
|
||
| # The demo site at https://labs.mapbox.com/to-color/ (previously deployed by Publisher). | ||
| - name: Build demo site | ||
| run: npm run build | ||
|
|
||
| - name: Configure AWS credentials | ||
| uses: mapbox/gha@action-configure-aws-credentials-v5 | ||
| with: | ||
| target-account-id: ${{ vars.AWS_ACCOUNT_ID_DEFAULT }} | ||
| role-to-assume: to-color-s3 | ||
|
|
||
| - name: Deploy demo site to staging | ||
| run: | | ||
| aws s3 sync _site "s3://${{ fromJson(env.bucket).staging }}" --exclude "*.html" --cache-control "max-age=120" | ||
| aws s3 sync _site "s3://${{ fromJson(env.bucket).staging }}" --exclude "*" --include "*.html" --cache-control "max-age=0" | ||
|
|
||
| - name: Deploy demo site to production | ||
| if: github.ref_name == 'main' | ||
| run: | | ||
| aws s3 sync _site "s3://${{ fromJson(env.bucket).production }}" --exclude "*.html" --cache-control "max-age=120" | ||
| aws s3 sync _site "s3://${{ fromJson(env.bucket).production }}" --exclude "*" --include "*.html" --cache-control "max-age=0" | ||
|
|
||
| - id: release | ||
| name: Create GitHub Release | ||
| continue-on-error: true | ||
| if: steps.version.outputs.skip != 'true' && steps.version.outputs.npm_publish_tag == 'latest' | ||
| env: | ||
| GH_TOKEN: ${{ github.token }} | ||
| VERSION: ${{ steps.version.outputs.version }} | ||
| run: gh release create "v$VERSION" --target "$GITHUB_SHA" --title "v$VERSION" --generate-notes | ||
|
|
||
| - name: Comment released version on PRs | ||
| continue-on-error: true | ||
| if: steps.release.outcome == 'success' | ||
| env: | ||
| GH_TOKEN: ${{ github.token }} | ||
| VERSION: ${{ steps.version.outputs.version }} | ||
| BEFORE_SHA: ${{ github.event.before }} | ||
| run: | | ||
| set -o pipefail | ||
| package_name="$(node -p 'require("./package.json").name')" | ||
| for sha in $(git rev-list "$BEFORE_SHA..$GITHUB_SHA"); do | ||
| gh api "repos/$GITHUB_REPOSITORY/commits/$sha/pulls" --jq '.[].number' | ||
| done | sort -u | while read -r pr; do | ||
| gh pr comment "$pr" --body "Released in \`$package_name@$VERSION\` (release [\`v$VERSION\`](https://github.com/$GITHUB_REPOSITORY/releases/tag/v$VERSION))." | ||
| done | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| 22 | ||
| 24 |
|
jcary741 marked this conversation as resolved.
Outdated
|
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be
publisher-production?maindoes not exist unless you are intended to change this but note we still want to publish builds to that branchThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep! That's in the post-merge TODO: