-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ci): Automate Docker image publication when merging on master (#…
…1142) * feat(ci): Publish Docker image to GitHub Packages from CI * chore(ci): Cleanup the Docker publish script * chore(ci): Remove reference to CircleCI * fix(ci): Remove useless config and dependency
- Loading branch information
1 parent
fd31d88
commit f0208ba
Showing
11 changed files
with
205 additions
and
107 deletions.
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