|
| 1 | +### Build a Release |
| 2 | + |
| 3 | +This is an example from th awesome-ci project you can find the original workflow [here](https://github.com/fullstack-devops/awesome-ci/blob/main/.github/workflows/Release.yaml) |
| 4 | + |
| 5 | +```yaml |
| 6 | +name: Publish Release |
| 7 | + |
| 8 | +on: |
| 9 | + push: |
| 10 | + branches: |
| 11 | + - "main" |
| 12 | + paths-ignore: |
| 13 | + - "README.md" |
| 14 | + - 'docs/**' |
| 15 | + - '.github/ISSUE_TEMPLATE/**' |
| 16 | + - '.github/PULL_REQUEST_TEMPLATE.md' |
| 17 | + |
| 18 | + |
| 19 | +jobs: |
| 20 | + generate_infos: |
| 21 | + runs-on: ubuntu-latest |
| 22 | + outputs: |
| 23 | + releaseid: $\{\{ steps.tag.outputs.releaseid \}\} |
| 24 | + version: $\{\{ steps.tag.outputs.version \}\} |
| 25 | + pr: $\{\{ steps.tag.outputs.pr \}\} |
| 26 | + steps: |
| 27 | + - name: Check out the repo |
| 28 | + uses: actions/checkout@v2 |
| 29 | + - name: Setup awesome-ci |
| 30 | + uses: fullstack-devops/awesome-ci-action@main |
| 31 | + |
| 32 | + - name: collect infos and create release |
| 33 | + run: | |
| 34 | + awesome-ci pr info |
| 35 | + awesome-ci release create -merge-sha $\{\{ github.sha \}\} |
| 36 | + env: |
| 37 | + GITHUB_TOKEN: $\{\{ secrets.GITHUB_TOKEN \}\} |
| 38 | + |
| 39 | + - name: collect infos |
| 40 | + id: tag |
| 41 | + shell: bash |
| 42 | + run: | |
| 43 | + echo "::set-output name=version::$ACI_VERSION" |
| 44 | + echo "::set-output name=pr::$ACI_PR" |
| 45 | + echo "::set-output name=releaseid::$ACI_RELEASE_ID" |
| 46 | +
|
| 47 | + build: |
| 48 | + runs-on: ubuntu-latest |
| 49 | + needs: generate_infos |
| 50 | + strategy: |
| 51 | + matrix: |
| 52 | + arch: ["amd64", "arm64"] |
| 53 | + steps: |
| 54 | + - name: Checkout code |
| 55 | + uses: actions/checkout@v2 |
| 56 | + - name: Set up Go |
| 57 | + uses: actions/setup-go@v2 |
| 58 | + with: |
| 59 | + go-version: 1.17 |
| 60 | + |
| 61 | + - name: Build "$\{\{ matrix.arch \}\}" |
| 62 | + run: go build -v -ldflags "-X main.version=$\{\{ needs.generate_infos.outputs.version \}\}" -o out/awesome-ci_$\{\{ needs.generate_infos.outputs.version \}\}_$\{\{ matrix.arch \}\} |
| 63 | + env: |
| 64 | + GOOS: linux |
| 65 | + GOARCH: "$\{\{ matrix.arch \}\}" |
| 66 | + |
| 67 | + - name: Cache build outputs |
| 68 | + uses: actions/cache@v2 |
| 69 | + env: |
| 70 | + cache-name: cache-outputs-modules |
| 71 | + with: |
| 72 | + path: out/ |
| 73 | + key: awesome-ci-$\{\{ github.sha \}\}-$\{\{ hashFiles('out/awesome-ci*') \}\} |
| 74 | + restore-keys: | |
| 75 | + awesome-ci-$\{\{ github.sha \}\} |
| 76 | +
|
| 77 | + publish_release: |
| 78 | + runs-on: ubuntu-latest |
| 79 | + needs: [generate_infos, build] |
| 80 | + steps: |
| 81 | + - name: Checkout code |
| 82 | + uses: actions/checkout@v2 |
| 83 | + - name: Setup awesome-ci |
| 84 | + uses: fullstack-devops/awesome-ci-action@main |
| 85 | + |
| 86 | + - name: get cached build outputs |
| 87 | + uses: actions/cache@v2 |
| 88 | + env: |
| 89 | + cache-name: cache-outputs-modules |
| 90 | + with: |
| 91 | + path: out/ |
| 92 | + key: awesome-ci-$\{\{ github.sha \}\} |
| 93 | + |
| 94 | + - name: Publish Release |
| 95 | + run: awesome-ci release publish -releaseid "$ACI_RELEASE_ID" -assets "file=out/$ARTIFACT1,file=out/$ARTIFACT2" |
| 96 | + env: |
| 97 | + GITHUB_TOKEN: $\{\{ secrets.GITHUB_TOKEN \}\} |
| 98 | + ACI_RELEASE_ID: $\{\{ needs.generate_infos.outputs.releaseid \}\} |
| 99 | + ARTIFACT1: awesome-ci_$\{\{ needs.generate_infos.outputs.version \}\}_amd64 |
| 100 | + ARTIFACT2: awesome-ci_$\{\{ needs.generate_infos.outputs.version \}\}_arm64 |
| 101 | +``` |
| 102 | +
|
| 103 | +You need more examples? Please open an issue! |
0 commit comments