-
Notifications
You must be signed in to change notification settings - Fork 22
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
feat(ci): Automate Docker image publication when merging on master #1142
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
60c8079
feat(ci): Publish Docker image to GitHub Packages from CI
pixelastic 350ee6c
chore(ci): Cleanup the Docker publish script
pixelastic 412d097
chore(ci): Remove reference to CircleCI
pixelastic ae34a18
fix(ci): Remove useless config and dependency
pixelastic 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 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 |
---|---|---|
|
@@ -15,7 +15,6 @@ cypress/ | |
.git/ | ||
.github/ | ||
.githooks/ | ||
.circleci/ | ||
.husky/ | ||
.nodemon.json | ||
.editorconfig | ||
|
This file contains 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,49 @@ | ||
name: Publish | ||
run-name: 🚀 Commit on ${{ github.ref_name }} | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
|
||
jobs: | ||
validate: | ||
name: 🤖 Validate | ||
uses: ./.github/workflows/validate.yml | ||
publish: | ||
name: 📦 Publish | ||
needs: validate | ||
runs-on: ubuntu-latest | ||
permissions: | ||
# To commit on the repo and add the tag | ||
contents: write | ||
# To publish the Docker image to GitHub Packages | ||
packages: write | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
steps: | ||
- name: 📁 Checkout code | ||
uses: actions/checkout@v4 | ||
|
||
- name: ⚙️ Setup node | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: '18.18' | ||
cache: 'yarn' | ||
|
||
- name: 📦 Install dependencies | ||
run: yarn install --frozen-lockfile | ||
|
||
- name: ❓ Check if a new version needs to be published | ||
id: publish-check | ||
continue-on-error: true | ||
run: yarn publish:check | ||
|
||
- name: 🆙 Bump version, tag commit, publish GitHub Release | ||
if: ${{ steps.publish-check.outcome == 'success' }} | ||
run: yarn publish:github | ||
|
||
- name: 🐋 Publish Docker image | ||
if: ${{ steps.publish-check.outcome == 'success' }} | ||
run: yarn publish:docker |
This file contains 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 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 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 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 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,50 @@ | ||
/* eslint-disable import/no-commonjs */ | ||
/* eslint-disable no-console */ | ||
/* eslint-disable no-process-exit */ | ||
/* eslint-disable @typescript-eslint/no-var-requires */ | ||
const { Writable } = require('node:stream'); | ||
|
||
const semanticRelease = require('semantic-release'); | ||
|
||
(async () => { | ||
console.log('Analyzing commits since last version...'); | ||
|
||
const stream = new Writable({ | ||
write(_chunk, _encoding, callback) { | ||
setImmediate(callback); | ||
}, | ||
}); | ||
|
||
// Execute semantic-release with only the commit-analyzer step, to see if | ||
// a new release is needed | ||
const { nextRelease } = await semanticRelease( | ||
{ | ||
dryRun: true, | ||
plugins: ['@semantic-release/commit-analyzer'], | ||
verifyConditions: [], | ||
analyzeCommits: ['@semantic-release/commit-analyzer'], | ||
verifyRelease: [], | ||
generateNotes: [], | ||
prepare: [], | ||
publish: [], | ||
addChannel: [], | ||
success: [], | ||
fail: [], | ||
}, | ||
// Redirect output to new streams, to make the script silent | ||
{ | ||
stdout: stream, | ||
stderr: stream, | ||
} | ||
); | ||
|
||
// Exit with 0 if a new version must be released, 1 if nothing to do | ||
if (nextRelease?.version) { | ||
console.log( | ||
`Commits analyzed warrant a release of version ${nextRelease.version}` | ||
); | ||
process.exit(0); | ||
} | ||
console.log('No new version to publish'); | ||
process.exit(1); | ||
})(); |
This file contains 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,38 @@ | ||
#!/bin/sh | ||
# Publish the project on GitHub Packages | ||
# See: https://github.com/algolia/npm-search/pkgs/container/npm-search | ||
# | ||
# This script will be automatically run from GitHub Actions on each commits on | ||
# the main branch that warrants a release (ie. feat() and fix() commits). | ||
# | ||
# You can also run the script locally, but you'll need a GITHUB_TOKEN with the | ||
# write:packages scope. | ||
# See: https://github.com/settings/tokens | ||
set -e | ||
|
||
# Get version from package.json | ||
version=$(node -e "console.log(require('./package.json').version)") | ||
echo "Publishing: $version" | ||
echo "" | ||
|
||
# Build the image | ||
docker build \ | ||
--platform linux/amd64 \ | ||
--label "org.opencontainers.image.source=https://github.com/algolia/npm-search" \ | ||
--tag "ghcr.io/algolia/npm-search" \ | ||
--tag "ghcr.io/algolia/npm-search:${version}" \ | ||
. | ||
|
||
# Login to ghcr.io | ||
echo "${GITHUB_TOKEN}" | | ||
docker login ghcr.io \ | ||
--username $ \ | ||
--password-stdin | ||
|
||
# Push the image | ||
docker push "ghcr.io/algolia/npm-search" | ||
docker push "ghcr.io/algolia/npm-search:${version}" | ||
|
||
# Output | ||
echo "Version $version published" | ||
echo "https://github.com/algolia/npm-search/pkgs/container/npm-search" |
This file contains 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,10 @@ | ||
#!/bin/sh | ||
# Publish a new version on GitHub, including: | ||
# - Update package.json and CHANGELOG.md with new version and changes | ||
# - Tag the commit with the version number | ||
# - Release the source code on GitHub Releases (https://github.com/algolia/npm-search/releases) | ||
# | ||
# This script doesn't do anything if there is no new version to publish | ||
set -e | ||
|
||
yarn run semantic-release |
This file contains 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
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.
this could just be:
and the file removed
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.
Right. I initially had the external script because there was a bit more code before and after, but you're right that it can now be simplified