-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented new CI method. This was copied directly from the [CI file from `auto-merge-bot`](https://github.com/paritytech/auto-merge-bot/blob/main/.github/workflows/release.yml)
- Loading branch information
Showing
1 changed file
with
42 additions
and
74 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -7,6 +7,7 @@ on: | |
|
||
env: | ||
IMAGE_NAME: action | ||
REGISTRY: ghcr.io | ||
|
||
jobs: | ||
test-image: | ||
|
@@ -36,93 +37,60 @@ jobs: | |
env: | ||
FILE_NAME: ".github/workflows/review-bot.yml" | ||
|
||
test-versions: | ||
compare-versions: | ||
runs-on: ubuntu-latest | ||
outputs: | ||
version: ${{ steps.verification.outputs.VERSION }} | ||
exists: ${{ steps.checkTag.outputs.exists }} | ||
steps: | ||
- uses: actions/[email protected] | ||
- name: Extract package.json version | ||
id: package_version | ||
run: echo "VERSION=$(jq '.version' -r package.json)" >> $GITHUB_OUTPUT | ||
- name: Extract action.yml version | ||
uses: mikefarah/yq@master | ||
id: action_image | ||
with: | ||
cmd: yq '.runs.image' 'action.yml' | ||
- name: Parse action.yml version | ||
id: action_version | ||
run: | | ||
echo "IMAGE_VERSION=$(echo $IMAGE_URL | cut -d: -f3)" >> $GITHUB_OUTPUT | ||
env: | ||
IMAGE_URL: ${{ steps.action_image.outputs.result }} | ||
# Compare that the versions contain the same name | ||
- name: Compare versions | ||
run: | | ||
echo "Verifying that $IMAGE_VERSION from action.yml is the same as $PACKAGE_VERSION from package.json" | ||
[[ $IMAGE_VERSION == $PACKAGE_VERSION ]] | ||
env: | ||
IMAGE_VERSION: ${{ steps.action_version.outputs.IMAGE_VERSION }} | ||
PACKAGE_VERSION: ${{ steps.package_version.outputs.VERSION }} | ||
id: verification | ||
uses: Bullrich/compare-version-on-action@main | ||
with: | ||
version: ${{ steps.package_version.outputs.VERSION }} | ||
# Verifies if there is a tag with that version number | ||
- uses: mukunku/[email protected] | ||
if: steps.verification.outputs.VERSION | ||
id: checkTag | ||
with: | ||
tag: v${{ steps.package_version.outputs.VERSION }} | ||
|
||
tag: | ||
if: github.event_name == 'push' | ||
needs: [test-image, test-versions] | ||
publish: | ||
if: github.event_name == 'push' && needs.compare-versions.outputs.exists == 'false' | ||
needs: [test-image, compare-versions] | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: write | ||
outputs: | ||
tagcreated: ${{ steps.autotag.outputs.tagcreated }} | ||
tagname: ${{ steps.autotag.outputs.tagname }} | ||
packages: write | ||
steps: | ||
- uses: actions/[email protected] | ||
with: | ||
fetch-depth: 0 | ||
- uses: butlerlogic/action-autotag@stable | ||
id: autotag | ||
with: | ||
head_branch: master | ||
tag_prefix: "v" | ||
- name: Tag version and create release | ||
run: gh release create $VERSION --generate-notes | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
- name: Changelog | ||
uses: Bullrich/[email protected] | ||
id: Changelog | ||
env: | ||
REPO: ${{ github.repository }} | ||
- name: Create Release | ||
if: steps.autotag.outputs.tagname != '' | ||
uses: actions/create-release@latest | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
VERSION: v${{ needs.compare-versions.outputs.version }} | ||
GH_TOKEN: ${{ github.token }} | ||
- name: Log in to the Container registry | ||
uses: docker/login-action@v3 | ||
with: | ||
tag_name: ${{ steps.autotag.outputs.tagname }} | ||
release_name: Release ${{ steps.autotag.outputs.tagname }} | ||
body: | | ||
${{ steps.Changelog.outputs.changelog }} | ||
publish: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
packages: write | ||
needs: [tag] | ||
if: needs.tag.outputs.tagname != '' | ||
steps: | ||
registry: ${{ env.REGISTRY }} | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
- name: Extract metadata (tags, labels) for Docker | ||
id: meta | ||
uses: docker/metadata-action@v5 | ||
with: | ||
images: ${{ env.REGISTRY }}/${{ github.repository }}/${{ env.IMAGE_NAME }} | ||
tags: ${{ needs.compare-versions.outputs.version }} | ||
- uses: actions/checkout@v3 | ||
- name: Build image | ||
run: docker build . --file Dockerfile --tag $IMAGE_NAME | ||
- name: Log into registry | ||
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login docker.pkg.github.com -u ${{ github.actor }} --password-stdin | ||
- name: Push image | ||
run: | | ||
IMAGE_ID=docker.pkg.github.com/${{ github.repository }}/$IMAGE_NAME | ||
# Change all uppercase to lowercase | ||
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]') | ||
# Strip git ref prefix from version | ||
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,') | ||
# Strip "v" prefix from tag name | ||
[[ ! -z $TAG ]] && VERSION=$(echo $TAG | sed -e 's/^v//') | ||
# Use Docker `latest` tag convention | ||
[ "$VERSION" == "main" ] && VERSION=latest | ||
echo IMAGE_ID=$IMAGE_ID | ||
echo VERSION=$VERSION | ||
docker tag $IMAGE_NAME $IMAGE_ID:$VERSION | ||
docker push $IMAGE_ID:$VERSION | ||
env: | ||
TAG: ${{ needs.tag.outputs.tagname }} | ||
- name: Build and push Docker image | ||
uses: docker/build-push-action@v5 | ||
with: | ||
context: . | ||
push: true | ||
tags: ${{ steps.meta.outputs.tags }} | ||
labels: ${{ steps.meta.outputs.labels }} |