From 0c8c98072d390f9373b78b331f972e566644a2a6 Mon Sep 17 00:00:00 2001 From: yimysty Date: Mon, 7 Feb 2022 09:43:38 -0800 Subject: [PATCH] add release process --- .github/release-drafter.yml | 38 ++++++++ .github/workflows/docker-publish.yml | 54 ++++------- .../workflows/release-new-action-version.yml | 54 +++++++++++ .github/workflows/test.yml | 95 +++++++++++++------ action.yml.erb | 32 ------- bin/render_action_metadata | 19 ---- 6 files changed, 175 insertions(+), 117 deletions(-) create mode 100644 .github/release-drafter.yml create mode 100644 .github/workflows/release-new-action-version.yml delete mode 100644 action.yml.erb delete mode 100755 bin/render_action_metadata diff --git a/.github/release-drafter.yml b/.github/release-drafter.yml new file mode 100644 index 0000000..c50c1e1 --- /dev/null +++ b/.github/release-drafter.yml @@ -0,0 +1,38 @@ +--- +name-template: 'v$RESOLVED_VERSION' +tag-template: 'v$RESOLVED_VERSION' +template: | + # Changelog + $CHANGES + See details of [all code changes](https://github.com/actions/jekyll-build-pages/compare/$PREVIOUS_TAG...v$RESOLVED_VERSION) since previous release +categories: + - title: '🚀 Features' + labels: + - 'feature' + - 'enhancement' + - title: '🐛 Bug Fixes' + labels: + - 'fix' + - 'bugfix' + - 'bug' + - title: '🧰 Maintenance' + labels: + - 'infrastructure' + - 'automation' + - 'documentation' + - title: '🏎 Performance' + label: 'performance' +change-template: '- $TITLE @$AUTHOR (#$NUMBER)' +version-resolver: + major: + labels: + - 'type: breaking' + minor: + labels: + - 'type: enhancement' + patch: + labels: + - 'type: bug' + - 'type: maintenance' + - 'type: documentation' + default: patch diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml index 9c3b0eb..3123f2f 100644 --- a/.github/workflows/docker-publish.yml +++ b/.github/workflows/docker-publish.yml @@ -9,20 +9,9 @@ on: push: branches: - 'main' - paths-ignore: - - 'README.md' - # Publish semver tags as releases. Allow for '-alpha' - # stage releases as well. + - 'feature-*' tags: - - 'v*.*.*-beta' - - 'v*.*.*-alpha' - 'v*' - pull_request: - branches: - - 'main' - paths-ignore: - - 'README.md' - env: # Use docker.io for Docker Hub if empty REGISTRY: ghcr.io @@ -40,15 +29,21 @@ jobs: # Login against a Docker registry except on PR # https://github.com/docker/login-action - name: Log into registry ${{ env.REGISTRY }} - if: github.event_name != 'pull_request' uses: docker/login-action@v1 with: registry: ${{ env.REGISTRY }} username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - - # Extract metadata (tags, labels) for Docker - # https://github.com/docker/metadata-action + - name: Generate Image Tags + id: generate-image-tags + run: | + # Generate tags for the image + if [[ "${{ github.ref_name }}" == "main" ]]; then + tags=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest + else + tags=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.ref_name }} + fi + echo "::set-output name=tags::$tags" - name: Extract Docker metadata id: meta uses: docker/metadata-action@v3 @@ -62,24 +57,11 @@ jobs: with: context: . file: Dockerfile - push: ${{ github.event_name != 'pull_request' }} - tags: ${{ steps.meta.outputs.tags }} + push: true + tags: ${{ steps.generate-image-tags.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} - - - name: Render Action Metadata - if: ${{ github.event_name != 'pull_request' }} - run: | - ./bin/render_action_metadata "docker://ghcr.io/actions/jekyll-build-pages:${{ github.ref_name }}" > action.yml - git add action.yml - git config --local user.name "github-actions[bot]" - git config --local user.email "github-actions[bot]@users.noreply.github.com" - git commit -m "Add generated action.yml 🤖" - if [[ '${{ github.ref_type }}' == 'tag' ]]; then - echo "Pushing tag ${{ github.ref_name }}" - git tag -f ${{ github.ref_name }} - git push -f origin ${{ github.ref_name }} - else - echo "Pushing branch ${{ github.ref_name }}" - git push origin ${{ github.ref_name }} - fi - + # Drafts your next Release notes as Pull Requests are merged into "main" + - uses: release-drafter/release-drafter@v5 + if: github.ref_name == 'main' + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/release-new-action-version.yml b/.github/workflows/release-new-action-version.yml new file mode 100644 index 0000000..373c1a6 --- /dev/null +++ b/.github/workflows/release-new-action-version.yml @@ -0,0 +1,54 @@ +name: Release new action version +on: + release: + types: [edited] + workflow_dispatch: + inputs: + TAG_NAME: + description: 'Tag name that the major tag will point to' + required: true + +env: + TAG_NAME: ${{ github.event.inputs.TAG_NAME || github.event.release.tag_name }} + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +jobs: + verify_release: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v2 + - name: Grep action.yaml content + id: grep-image-content + run: | + image=$(grep -E "jekyll-build-pages.*\'" action.yml) + echo "::set-output name=image::$image" + - uses: actions-ecosystem/action-regex-match@v2 + id: regex-match + with: + text: ${{ steps.grep-image-content.outputs.image }} + regex: "jekyll-build-pages:(.*)'" + - name: Version match + run: | + if [ "${{ steps.regex-match.outputs.group1 }}" != "${{ env.TAG_NAME }}" ]; then + echo "version mismatch. action.yaml with version ${{ steps.regex-match.outputs.group1 }} Tag version ${{ env.TAG_NAME }}"; + exit 1 + fi + - name: Verify image published + run: docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.TAG_NAME }} + update_tag: + needs: verify_release + name: Update the major tag to include the ${{ github.event.inputs.TAG_NAME || github.event.release.tag_name }} changes + environment: + name: releaseNewActionVersion + runs-on: ubuntu-latest + outputs: + major_tag: ${{ steps.update-major-tag.outputs.major-tag }} + steps: + - name: Update the ${{ env.TAG_NAME }} tag + id: update-major-tag + uses: actions/publish-action@v0.1.0 + with: + source-tag: ${{ env.TAG_NAME }} + slack-webhook: ${{ secrets.SLACK_WEBHOOK }} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ce05365..6d5a53b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -9,20 +9,45 @@ on: pull_request: paths-ignore: - 'README.md' +env: + # Use docker.io for Docker Hub if empty + REGISTRY: ghcr.io + # github.repository as / + IMAGE_NAME: ${{ github.repository }} jobs: + resolve-image-tag: + runs-on: ubuntu-latest + outputs: + tag: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.regex-match.outputs.group1 }} + steps: + - name: Checkout repository + uses: actions/checkout@v2 + - name: grep action.yaml content + id: grep-image-content + run: | + image=$(grep -E "jekyll-build-pages.*\'" action.yml) + echo "::set-output name=image::$image" + - uses: actions-ecosystem/action-regex-match@v2 + id: regex-match + with: + text: ${{ steps.grep-image-content.outputs.image }} + regex: "jekyll-build-pages:(.*)'" + test-simple: + needs: resolve-image-tag runs-on: ubuntu-latest env: TEST_NAME: simple steps: - name: Checkout repository uses: actions/checkout@v2 - - - name: Render Action Metadata - run: | - ./bin/render_action_metadata Dockerfile > action.yml - + - name: Build local docker image + uses: docker/build-push-action@v2 + with: + context: . + file: Dockerfile + tags: ${{ needs.resolve-image-tag.outputs.tag }} - name: Test ${{ env.TEST_NAME }} Project uses: ./ with: @@ -37,17 +62,19 @@ jobs: path: ./test_projects/${{ env.TEST_NAME }} test-readme: + needs: resolve-image-tag runs-on: ubuntu-latest env: TEST_NAME: readme steps: - name: Checkout repository uses: actions/checkout@v2 - - - name: Render Action Metadata - run: | - ./bin/render_action_metadata Dockerfile > action.yml - + - name: Build local docker image + uses: docker/build-push-action@v2 + with: + context: . + file: Dockerfile + tags: ${{ needs.resolve-image-tag.outputs.tag }} - name: Test ${{ env.TEST_NAME }} Project uses: ./ with: @@ -62,17 +89,19 @@ jobs: path: ./test_projects/${{ env.TEST_NAME }} test-octicons: + needs: resolve-image-tag runs-on: ubuntu-latest env: TEST_NAME: octicons steps: - name: Checkout repository uses: actions/checkout@v2 - - - name: Render Action Metadata - run: | - ./bin/render_action_metadata Dockerfile > action.yml - + - name: Build local docker image + uses: docker/build-push-action@v2 + with: + context: . + file: Dockerfile + tags: ${{ needs.resolve-image-tag.outputs.tag }} - name: Test ${{ env.TEST_NAME }} Project uses: ./ with: @@ -87,17 +116,19 @@ jobs: path: ./test_projects/${{ env.TEST_NAME }} test-mojombo: + needs: resolve-image-tag runs-on: ubuntu-latest env: TEST_NAME: mojombo steps: - name: Checkout repository uses: actions/checkout@v2 - - - name: Render Action Metadata - run: | - ./bin/render_action_metadata Dockerfile > action.yml - + - name: Build local docker image + uses: docker/build-push-action@v2 + with: + context: . + file: Dockerfile + tags: ${{ needs.resolve-image-tag.outputs.tag }} - name: Test ${{ env.TEST_NAME }} Project uses: ./ with: @@ -112,17 +143,19 @@ jobs: path: ./test_projects/${{ env.TEST_NAME }} test-themes: + needs: resolve-image-tag runs-on: ubuntu-latest env: TEST_NAME: themes steps: - name: Checkout repository uses: actions/checkout@v2 - - - name: Render Action Metadata - run: | - ./bin/render_action_metadata Dockerfile > action.yml - + - name: Build local docker image + uses: docker/build-push-action@v2 + with: + context: . + file: Dockerfile + tags: ${{ needs.resolve-image-tag.outputs.tag }} - name: Test ${{ env.TEST_NAME }} Project uses: ./ with: @@ -137,17 +170,19 @@ jobs: path: ./test_projects/${{ env.TEST_NAME }} test-jekyll-include-cache: + needs: resolve-image-tag runs-on: ubuntu-latest env: TEST_NAME: jekyll-include-cache steps: - name: Checkout repository uses: actions/checkout@v2 - - - name: Render Action Metadata - run: | - ./bin/render_action_metadata Dockerfile > action.yml - + - name: Build local docker image + uses: docker/build-push-action@v2 + with: + context: . + file: Dockerfile + tags: ${{ needs.resolve-image-tag.outputs.tag }} - name: Test ${{ env.TEST_NAME }} Project uses: ./ with: diff --git a/action.yml.erb b/action.yml.erb deleted file mode 100644 index 45e7666..0000000 --- a/action.yml.erb +++ /dev/null @@ -1,32 +0,0 @@ -# Generated from action.yml.erb -# <%= nonce %> -name: 'Pages Jekyll' -description: 'A simple GitHub Action for producing Jekyll build artifacts compatible with GitHub Pages' -inputs: - source: - description: 'Directory where the source files reside.' - required: false - default: ./ - destination: - description: 'Output directory of the build. Although it can be nested inside the source, it cannot be the same as the source directory.' - required: false - default: ./_site - future: - description: 'Publishes posts with a future date. When set to true, the build is made with the --future option which overrides the future option that may be set in a Jekyll configuration file.' - required: false - default: false - build_revision: - description: 'The SHA-1 of the git commit for which the build is running. Default to GITHUB_SHA.' - required: false - default: ${{ github.sha }} - verbose: - description: 'Verbose output' - required: false - default: true - token: - description: 'GitHub token' - required: true - default: ${{ github.token }} -runs: - using: 'docker' - image: '<%= pages_action_url %>' diff --git a/bin/render_action_metadata b/bin/render_action_metadata deleted file mode 100755 index b798542..0000000 --- a/bin/render_action_metadata +++ /dev/null @@ -1,19 +0,0 @@ -#! /usr/bin/env ruby - -# Internal: Generate an action.yml metadata file using the inputs -# -# pages_action_url - Docker image URL to be used as the base action image. - -require 'erb' -require 'securerandom' - -nonce = SecureRandom.hex -pages_action_url = ARGV[0] - -action_erb_path = File.dirname(__FILE__) + '/../action.yml.erb' - -result = File.open(action_erb_path, 'r') do |file| - ERB.new(file.read).result(binding) -end - -puts result