From 4d8c6f627e146b89809d338d5a64cfb469839516 Mon Sep 17 00:00:00 2001 From: Javier Bullrich Date: Sat, 30 Sep 2023 14:02:19 +0200 Subject: [PATCH] Continuous deployment (#5) Created deploy script to automatically deploy new versions to GitHub packages using Docker. This resolves #2 Copied from paritytech/auto-merge-bot#16 --- .github/workflows/release.yml | 76 +++++++++++++++++++++++++++++++++++ README.md | 11 +++++ 2 files changed, 87 insertions(+) create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..e19978b --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,76 @@ +name: Publish package to GitHub Packages +on: + push: + branches: + - main + pull_request: + +env: + IMAGE_NAME: action + REGISTRY: ghcr.io + +jobs: + test-image: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3.3.0 + - name: Check that the image builds + run: docker build . --file Dockerfile + + compare-versions: + runs-on: ubuntu-latest + outputs: + version: ${{ steps.verification.outputs.VERSION }} + exists: ${{ steps.checkTag.outputs.exists }} + steps: + - uses: actions/checkout@v3.3.0 + - name: Extract package.json version + id: package_version + run: echo "VERSION=$(jq '.version' -r package.json)" >> $GITHUB_OUTPUT + # Compare that the versions contain the same name + - name: Compare versions + 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/tag-exists-action@v1.4.0 + if: steps.verification.outputs.VERSION + id: checkTag + with: + tag: v${{ steps.package_version.outputs.VERSION }} + + publish: + if: github.event_name == 'push' && needs.compare-versions.outputs.exists == 'false' + needs: [test-image, compare-versions] + runs-on: ubuntu-latest + permissions: + contents: write + packages: write + steps: + - uses: actions/checkout@v3.3.0 + - name: Tag version and create release + run: gh release create $VERSION --generate-notes + env: + VERSION: ${{ needs.compare-versions.outputs.version }} + GH_TOKEN: ${{ github.token }} + - name: Log in to the Container registry + uses: docker/login-action@v3 + with: + 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 and push Docker image + uses: docker/build-push-action@v5 + with: + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} diff --git a/README.md b/README.md index df10f66..01e2411 100644 --- a/README.md +++ b/README.md @@ -45,3 +45,14 @@ They are: - Example: `[{"address":"1e2345...",rank: 4, "githubHandle":"user-1"},{"address":"1e4532...",rank: 3, "githubHandle":"user-2"},{"address":"1e8335...",rank: 6}]` - `github-handles`: All the fellows handles separated by commas - Example: `user-1,user-2,user-3` + +## Deployment + +To deploy a new version you need to update two files: +- [`package.json`](./package.json): Update the version number. +- [`action.yml`](./action.yml): Update the image number in `runs.image`. +**Important**: Both versions must have the same number. + +When a commit is pushed to the main branch and the versions have changed, the system will automatically tag the commit and release a new package with such version. + +You can find all the available versions in the [release section](./releases).